You are here

public function AcquiadamAsset::getMetadata in Media: Acquia DAM 8

Gets the metadata for the given entity.

Parameters

\Drupal\media\MediaInterface $media: The media entity to get metadata from.

string $name: The metadata item to get the value of.

Return value

mixed|null The metadata value or NULL if unset.

Overrides MediaSourceBase::getMetadata

File

src/Plugin/media/Source/AcquiadamAsset.php, line 181

Class

AcquiadamAsset
Provides media type plugin for Acquia DAM assets.

Namespace

Drupal\media_acquiadam\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $name) {
  if (empty($this->currentAsset)) {
    $asset = $this->assetMediaFactory
      ->get($media)
      ->getAsset();
    if (empty($asset)) {
      return NULL;
    }
    $this->currentAsset = $asset;
  }
  switch ($name) {
    case 'default_name':
      return parent::getMetadata($media, 'default_name');
    case 'thumbnail_uri':
      return $this->assetImageHelper
        ->getThumbnail($this->currentAsset, $this->assetMediaFactory
        ->get($media)
        ->getFile());
    case 'file':
      $file = $this->assetMediaFactory
        ->get($media)
        ->getFile();
      $is_file = !empty($file) && $file instanceof FileInterface;
      return $is_file ? $file
        ->id() : NULL;
    default:
      return $this->assetMetadataHelper
        ->getMetadataFromAsset($this->currentAsset, $name);
  }
}