media.api.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @file
  4. * Hooks related to Media and its plugins.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alters the information provided in \Drupal\media\Annotation\MediaSource.
  12. *
  13. * @param array $sources
  14. * The array of media source plugin definitions, keyed by plugin ID.
  15. */
  16. function hook_media_source_info_alter(array &$sources) {
  17. $sources['youtube']['label'] = t('Youtube rocks!');
  18. }
  19. /**
  20. * Alters an oEmbed resource URL before it is fetched.
  21. *
  22. * @param array $parsed_url
  23. * A parsed URL, as returned by \Drupal\Component\Utility\UrlHelper::parse().
  24. * @param \Drupal\media\OEmbed\Provider $provider
  25. * The oEmbed provider for the resource.
  26. *
  27. * @see \Drupal\media\OEmbed\UrlResolverInterface::getResourceUrl()
  28. */
  29. function hook_oembed_resource_url_alter(array &$parsed_url, \Drupal\media\OEmbed\Provider $provider) {
  30. // Always serve YouTube videos from youtube-nocookie.com.
  31. if ($provider->getName() === 'YouTube') {
  32. $parsed_url['path'] = str_replace('://youtube.com/', '://youtube-nocookie.com/', $parsed_url['path']);
  33. }
  34. }
  35. /**
  36. * @} End of "addtogroup hooks".
  37. */