function hook_oembed_resource_url_alter

Same name and namespace in other branches
  1. 9 core/modules/media/media.api.php \hook_oembed_resource_url_alter()
  2. 8.9.x core/modules/media/media.api.php \hook_oembed_resource_url_alter()
  3. 11.x core/modules/media/media.api.php \hook_oembed_resource_url_alter()

Alters an oEmbed resource URL before it is fetched.

Parameters

array $parsed_url: A parsed URL, as returned by \Drupal\Component\Utility\UrlHelper::parse().

\Drupal\media\OEmbed\Provider $provider: The oEmbed provider for the resource.

See also

\Drupal\media\OEmbed\UrlResolverInterface::getResourceUrl()

Related topics

2 functions implement hook_oembed_resource_url_alter()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

MediaTestOembedHooks::oembedResourceUrlAlter in core/modules/media/tests/modules/media_test_oembed/src/Hook/MediaTestOembedHooks.php
Implements hook_oembed_resource_url_alter().
media_test_oembed_oembed_resource_url_alter in core/modules/media/tests/modules/media_test_oembed/media_test_oembed.module
Implements hook_oembed_resource_url_alter().
1 invocation of hook_oembed_resource_url_alter()
UrlResolver::getResourceUrl in core/modules/media/src/OEmbed/UrlResolver.php
Builds the resource URL for a media asset URL.

File

core/modules/media/media.api.php, line 33

Code

function hook_oembed_resource_url_alter(array &$parsed_url, \Drupal\media\OEmbed\Provider $provider) {
  // Always serve YouTube videos from youtube-nocookie.com.
  if ($provider->getName() === 'YouTube') {
    $parsed_url['path'] = str_replace('://youtube.com/', '://youtube-nocookie.com/', $parsed_url['path']);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.