You are here

public function VarbaseMediaGallery::getMetadata in Varbase Media 8.7

Same name and namespace in other branches
  1. 9.0.x src/Plugin/media/Source/VarbaseMediaGallery.php \Drupal\varbase_media\Plugin\media\Source\VarbaseMediaGallery::getMetadata()

Gets the value for a metadata attribute for a given media item.

Parameters

\Drupal\media\MediaInterface $media: A media item.

string $attribute_name: Name of the attribute to fetch.

Return value

mixed|null Metadata attribute value or NULL if unavailable.

Overrides MediaSourceBase::getMetadata

File

src/Plugin/media/Source/VarbaseMediaGallery.php, line 37

Class

VarbaseMediaGallery
Provides media type plugin for Gallery.

Namespace

Drupal\varbase_media\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $name) {
  $source_field = $this->configuration['source_field'];
  switch ($name) {
    case 'default_name':
      $length = $this
        ->getMetadata($media, 'length');
      if (!empty($length)) {
        return $this
          ->formatPlural($length, '1 media item, created on @date', '@count media items, created on @date', [
          '@date' => \Drupal::service('date.formatter')
            ->format($media
            ->getCreatedTime(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
        ]);
      }
      return parent::getMetadata($media, 'default_name');
    case 'length':
      return $media->{$source_field}
        ->count();
    case 'thumbnail_uri':
      return parent::getMetadata($media, 'thumbnail_uri');
    default:
      return parent::getMetadata($media, $name);
  }
}