- π¬π§United Kingdom newaytech
Hi there - I'm getting an exact same issue with Vimeo URL parameters. I've put together the following code so far for Vimeo - and it's working - but I can't figure out where the "app_id" value is set - so feel the solution is fragile.
function neway_barrio_sass_preprocess_media_oembed_iframe(array &$variables) { $url = Drupal::request()->query->get('url'); $params = UrlHelper::parse($url)['query']; // Take each param and add together to make a param list separated by & $query = http_build_query($params); kint($url); kint($params); kint($query); $original = $variables["media"]->__toString(); kint($original); if (!empty($params)) { $original = str_replace('?app_id', '?' . $query . '&app_id', $original); } kint($original); $variables["media"] = IFrameMarkup::create($original); }
Hoping someone from the community can chime in with some insight. I'm going to explore "hook_oembed_resource_url_alter" next...
Usning Drupal 10.3.6
- πΊπΈUnited States jeffc518
Hi @newaytech - I ran into a similar issue here with Vimeo and thought I'd put my solution in here.
I decided to use regex inside mytheme_preprocess_media_oembed_iframe(). It makes some assumptions, such as the app_id query parameter will always be there, so you might want to do some sanity checks. I haven't had time yet.
It works on a Vimeo URL like https://player.vimeo.com/video/xxxxxxxxxx?app_id=xxxxxx
function greene_preprocess_media_oembed_iframe(&$variables) { $original = $variables['media']->__toString(); /** @var \Drupal\media\OEmbed\Resource $resource */ $resource = $variables['resource']; if ($resource->getProvider()->getName() === 'Vimeo') { $original = preg_replace('/(.*)(\?app_id=\d+)(.*)/', '$1$2&muted=1&autoplay=1$3', $original); $variables['media'] = \Drupal\media\IFrameMarkup::create($original); } }
This applies the muted and autoplay params needed to make the video loop.
- π¬π§United Kingdom newaytech
Hi @jeffc518 - thanks for checking in. I got the below back from Vimeo support (after about 5 iterations):
Thank you for your patience. The app_id parameter is used for our internal metrics and logging. The Video will stay play without it, however, this will always be part of the oEmbed html response.
So your regex (and my str replace) - should be robust enough....