public function BrightcoveVideo::getMetadata in Brightcove Video Connect 8.2
Same name and namespace in other branches
- 3.x modules/media_brightcove/src/Plugin/media/Source/BrightcoveVideo.php \Drupal\media_brightcove\Plugin\media\Source\BrightcoveVideo::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
- modules/
media_brightcove/ src/ Plugin/ media/ Source/ BrightcoveVideo.php, line 64
Class
- BrightcoveVideo
- Brightcove Video entity media source.
Namespace
Drupal\media_brightcove\Plugin\media\SourceCode
public function getMetadata(MediaInterface $media, $attribute_name) {
switch ($attribute_name) {
case 'thumbnail_uri':
// Have a decent default.
$uri = $this->configFactory
->get('media.settings')
->get('icon_base_uri') . '/no-thumbnail.png';
// Check if the source field is still present and populated.
$media_source = $media
->getSource();
/** @var \Drupal\brightcove\Entity\BrightcoveVideo $brightcove_video */
if ($brightcove_video = $media
->get($media_source
->getConfiguration()['source_field'])->entity) {
// Check if the thumbnail file is still present.
if ($thumbnail = $brightcove_video
->getThumbnail()) {
if ($thumbnail_file = File::load($thumbnail['target_id'])) {
$uri = $thumbnail_file
->getFileUri();
}
}
}
return $uri;
case 'name':
return $media
->get('name')
->get(0)
->getValue();
// TODO: Add cases for other metadata as/if needed.
default:
return parent::getMetadata($media, $attribute_name);
}
}