Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update Blazy Drupal module to make all videos not autoplay and use the nocookie url.
diff --git a/src/BlazyMedia.php b/src/BlazyMedia.php
index a996b32..7129204 100644
--- a/src/BlazyMedia.php
+++ b/src/BlazyMedia.php
@@ -46,6 +46,20 @@ class BlazyMedia {
$allow = $iframe_attributes['allow'] = 'autoplay; accelerometer; encrypted-media; gyroscope; picture-in-picture';
}
+ // Update Youtube to not be no-cookie and not autoplay.
+ if (strpos($iframe_attributes["data-src"], 'youtu') !== FALSE) {
+ $iframe_attributes["data-src"] = str_replace('autoplay=1', 'autoplay=0', $iframe_attributes["data-src"]);
+ $iframe_attributes["data-src"] = str_replace('youtube.com', 'youtube-nocookie.com', $iframe_attributes["data-src"]);
+ }
+
+ $player_attributes = [
+ 'class' => 'media__icon media__icon--play',
+ ];
+
+ if (isset($settings['autoplay_url'])) {
+ $player_attributes['data-url'] = $settings['autoplay_url'];
+ }
+
$player_attributes = [
'class' => 'media__icon media__icon--play',
'data-url' => $settings['autoplay_url'],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment