You are here

public function Photos::getMetadata in Album Photos 8.5

Same name and namespace in other branches
  1. 6.0.x src/Plugin/media/Source/Photos.php \Drupal\photos\Plugin\media\Source\Photos::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/Photos.php, line 34

Class

Photos
Photos album media source.

Namespace

Drupal\photos\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $attribute_name) {

  // @todo default thumbnail?
  $source_field = $this->configuration['source_field'];

  // If the source field is not required, it may be empty.
  if (!$source_field) {
    return parent::getMetadata($media, $attribute_name);
  }
  switch ($attribute_name) {
    case 'default_name':
      $nid = $media
        ->get($source_field)->target_id;
      $node = $this->entityTypeManager
        ->getStorage('node')
        ->load($nid);
      if ($node) {
        return $node
          ->getTitle();
      }
      return parent::getMetadata($media, $attribute_name);
    case 'thumbnail_uri':

    // @todo check cover_id?
    default:
      return parent::getMetadata($media, $attribute_name);
  }
}