You are here

public function Bynder::getMetadata in Bynder 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/media/Source/Bynder.php \Drupal\bynder\Plugin\media\Source\Bynder::getMetadata()
  2. 8.2 src/Plugin/media/Source/Bynder.php \Drupal\bynder\Plugin\media\Source\Bynder::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/Bynder.php, line 346

Class

Bynder
Provides media source plugin for Bynder.

Namespace

Drupal\bynder\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $name) {
  $remote_uuid = $this
    ->getSourceFieldValue($media);
  if ($name == 'uuid') {
    return $remote_uuid;
  }

  // Ensure the metadata information are fetched.
  if ($this
    ->ensureMetadata($media)) {
    switch ($name) {
      case 'video_preview_urls':
        return isset($this->metadata[$remote_uuid]['videoPreviewURLs']) ? $this->metadata[$remote_uuid]['videoPreviewURLs'] : FALSE;
      case 'thumbnail_urls':
        return isset($this->metadata[$remote_uuid]['thumbnails']) ? $this->metadata[$remote_uuid]['thumbnails'] : FALSE;
      case 'thumbnail_uri':
        if (!empty($this->metadata[$remote_uuid]['thumbnails']['webimage'])) {
          if ($this
            ->useRemoteImages()) {
            return $this->metadata[$remote_uuid]['thumbnails']['webimage'];
          }
          elseif ($file = system_retrieve_file($this->metadata[$remote_uuid]['thumbnails']['webimage'], NULL, TRUE)) {
            return $file
              ->getFileUri();
          }
        }
        return parent::getMetadata($media, 'thumbnail_uri');
      case 'created':
        return isset($this->metadata[$remote_uuid]['dateCreated']) ? $this->metadata[$remote_uuid]['dateCreated'] : FALSE;
      case 'modified':
        return isset($this->metadata[$remote_uuid]['dateModified']) ? $this->metadata[$remote_uuid]['dateModified'] : FALSE;
      case 'default_name':
        return isset($this->metadata[$remote_uuid]['name']) ? $this->metadata[$remote_uuid]['name'] : parent::getMetadata($media, 'default_name');
      default:
        return isset($this->metadata[$remote_uuid][$name]) ? $this->metadata[$remote_uuid][$name] : FALSE;
    }
  }
  return FALSE;
}