You are here

public function VideoEmbedField::getField in Video Embed Field 8

Gets a media-related field/value.

Parameters

MediaInterface $media: Media object.

string $name: Name of field to fetch.

Return value

mixed Field value or FALSE if data unavailable.

Overrides MediaTypeInterface::getField

File

modules/video_embed_media/src/Plugin/MediaEntity/Type/VideoEmbedField.php, line 112

Class

VideoEmbedField
Provides media type plugin for video embed field.

Namespace

Drupal\video_embed_media\Plugin\MediaEntity\Type

Code

public function getField(MediaInterface $media, $name) {
  if (!($url = $this
    ->getVideoUrl($media))) {
    return FALSE;
  }
  $provider = $this->providerManager
    ->loadProviderFromInput($url);
  $definition = $this->providerManager
    ->loadDefinitionFromInput($url);
  switch ($name) {
    case 'id':
      return $provider
        ->getIdFromInput($url);
    case 'source':
      return $definition['id'];
    case 'source_name':
      return $definition['id'];
    case 'image_local':
    case 'image_local_uri':
      return $this
        ->thumbnail($media);
  }
}