You are here

public function BlazyOEmbed::getMediaItem in Blazy 8.2

Gets the Media item thumbnail.

Parameters

array $data: The modified array containing settings, and to be video thumbnail item.

object $media: The core Media entity.

Overrides BlazyOEmbedInterface::getMediaItem

File

src/BlazyOEmbed.php, line 208

Class

BlazyOEmbed
Provides OEmbed integration.

Namespace

Drupal\blazy

Code

public function getMediaItem(array &$data, $media) {

  // Only proceed if we do have Media.
  if ($media
    ->getEntityTypeId() != 'media') {
    return;
  }
  BlazyMedia::mediaItem($data, $media);
  $settings = $data['settings'];

  // @todo support local video/ audio file, and other media sources.
  // @todo check for Resource::TYPE_PHOTO, Resource::TYPE_RICH, etc.
  switch ($settings['media_source']) {
    case 'oembed':
    case 'oembed:video':
    case 'video_embed_field':

      // Input url != embed url. For Youtube, /watch != /embed.
      if ($input_url = $media
        ->getSource()
        ->getSourceFieldValue($media)) {
        $settings['input_url'] = $input_url;
        $this
          ->build($settings);
      }
      break;
    case 'image':
      $settings['type'] = 'image';
      break;

    // No special handling for anything else for now, pass through.
    default:
      break;
  }

  // Do not proceed if it has type, already managed by theme_blazy().
  // Supports other Media entities: Facebook, Instagram, local video, etc.
  if (empty($settings['type']) && ($build = BlazyMedia::build($media, $settings))) {
    $data['content'][] = $build;
  }

  // Collect what's needed for clarity.
  $data['settings'] = $settings;
}