You are here

public function Video::getField in Media entity video 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

src/Plugin/MediaEntity/Type/Video.php, line 32

Class

Video
Provides media type plugin for Video.

Namespace

Drupal\media_entity_video\Plugin\MediaEntity\Type

Code

public function getField(MediaInterface $media, $name) {
  $source_field = $this->configuration['source_field'];

  // Get the file document.

  /** @var \Drupal\file\FileInterface $file */
  $file = $media->{$source_field}->entity;

  // Return the field.
  switch ($name) {
    case 'mime':
      return !$file->filemime
        ->isEmpty() ? $file
        ->getMimeType() : FALSE;
  }
  return FALSE;
}