Move autoplay setting to module

Created on 6 May 2024, 7 months ago

Currently i used a theme hook to set the autoplay off.
I need to integrate that into the module before i can release the new version.

Current theme template code

/**
 * Implements hook_preprocess_HOOK().
 * //https://lists.osu.edu/pipermail/drupal/2021-March/000490.html
 */
function pd7_radix_preprocess_media_oembed_iframe(array &$variables) {

  $resource = $variables['resource'];

  if ($resource->getProvider()->getName() === 'YouTube') {

    $iFrame = $variables['media']->__toString();

    // Switch domain to the youtube nocookie domain.
    if (stripos($iFrame, 'youtube.com') !== false){

      //nocookie we dont use because the button gives cookie rights
      //$newFrame = str_replace('youtube.com/', 'youtube-nocookie.com/', $iFrame);

      //autoplay and only show channel videos
      //autoplay because we hit ok for cookies
      $embed_code = str_replace('?feature=oembed', '?feature=oembed&autoplay=1&rel=0', $iFrame);

      //!!! do not do that src to data-src here! We swap that in the
      //gdpr_video_preprocess_field()
      //$embed_code = str_replace('src="', 'data-src="', $embed_code);

      $variables['media'] = IFrameMarkup::create($embed_code);
    }

    // get the max res image
    // save the image to the local filesystem
    // how to check if it is new and needs to be updated?
//    $url = $resource->getThumbnailUrl()->toString();
//    $thumb = explode('/', $url);
//    $vid_id = $thumb[4];
//    $thumb_max_res = "https://img.youtube.com/vi/" . $vid_id . "/maxresdefault.jpg";

      //we can also use the already existing eoembed thumnail
    //$stop=$resource->getThumbnailUrl();

    ///sites/funkkopfhoerer-infos.de/files/oembed_thumbnails/dtZXa9vlMpCpv1AIwdknXEr6fOU_RSWgOFjjhBk7FtA.jpg
    $ytOembed = '';
  }
}
📌 Task
Status

Active

Version

1.1

Component

Code

Created by

🇩🇪Germany marcoka

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024