public function MediaSourceBase::getSourceFieldValue in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldValue()
- 9 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldValue()
1 call to MediaSourceBase::getSourceFieldValue()
- OEmbed::getMetadata in core/
modules/ media/ src/ Plugin/ media/ Source/ OEmbed.php - Gets the value for a metadata attribute for a given media item.
File
- core/
modules/ media/ src/ MediaSourceBase.php, line 327
Class
- MediaSourceBase
- Base implementation of media source plugin.
Namespace
Drupal\mediaCode
public function getSourceFieldValue(MediaInterface $media) {
$source_field = $this->configuration['source_field'];
if (empty($source_field)) {
throw new \RuntimeException('Source field for media source is not defined.');
}
$items = $media
->get($source_field);
if ($items
->isEmpty()) {
return NULL;
}
$field_item = $items
->first();
return $field_item->{$field_item
->mainPropertyName()};
}