function MediaSourceBase::getSourceFieldValue

Same name in other branches
  1. 9 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldValue()
  2. 8.9.x core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldValue()
  3. 11.x core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldValue()

Overrides MediaSourceInterface::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 332

Class

MediaSourceBase
Base implementation of media source plugin.

Namespace

Drupal\media

Code

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()};
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.