function MediaSourceBase::getSourceFieldDefinition

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

Overrides MediaSourceInterface::getSourceFieldDefinition

File

core/modules/media/src/MediaSourceBase.php, line 269

Class

MediaSourceBase
Base implementation of media source plugin.

Namespace

Drupal\media

Code

public function getSourceFieldDefinition(MediaTypeInterface $type) {
    // Nothing to do if no source field is configured yet.
    $field = $this->configuration['source_field'];
    if ($field) {
        // Even if we do know the name of the source field, there is no
        // guarantee that it already exists.
        $fields = $this->entityFieldManager
            ->getFieldDefinitions('media', $type->id());
        return $fields[$field] ?? NULL;
    }
    return NULL;
}

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