Skip to content

Instantly share code, notes, and snippets.

@paulsheldrake
Created October 9, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsheldrake/4ab61a2dc8e164c8de49132c9c09f922 to your computer and use it in GitHub Desktop.
Save paulsheldrake/4ab61a2dc8e164c8de49132c9c09f922 to your computer and use it in GitHub Desktop.
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