media.api.php 1.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php

/**
 * @file
 * Hooks related to Media and its plugins.
 */

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Alters the information provided in \Drupal\media\Annotation\MediaSource.
 *
 * @param array $sources
 *   The array of media source plugin definitions, keyed by plugin ID.
 */
function hook_media_source_info_alter(array &$sources) {
  $sources['youtube']['label'] = t('Youtube rocks!');
}

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/**
 * Alters an oEmbed resource URL before it is fetched.
 *
 * @param array $parsed_url
 *   A parsed URL, as returned by \Drupal\Component\Utility\UrlHelper::parse().
 * @param \Drupal\media\OEmbed\Provider $provider
 *   The oEmbed provider for the resource.
 *
 * @see \Drupal\media\OEmbed\UrlResolverInterface::getResourceUrl()
 */
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']);
  }
}

40 41 42
/**
 * @} End of "addtogroup hooks".
 */