public function Photos::getMetadata in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 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 35
Class
- Photos
- Photos album media source.
Namespace
Drupal\photos\Plugin\media\SourceCode
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':
$nid = $media
->get($source_field)->target_id;
$node = $this->entityTypeManager
->getStorage('node')
->load($nid);
if (isset($node->album) && isset($node->album['cover_id'])) {
// Get cover image URI if available.
$cover_id = $node->album['cover_id'];
$photos_album = new PhotosAlbum($node
->id());
return $photos_album
->getCover($cover_id, TRUE);
}
default:
return parent::getMetadata($media, $attribute_name);
}
}