You are here

public function VideoEmbedField::getSourceFieldDefinition in Video Embed Field 8.2

Get the source field definition for a media type.

Parameters

\Drupal\media\MediaTypeInterface $type: A media type.

Return value

\Drupal\Core\Field\FieldDefinitionInterface|null The source field definition, or NULL if it doesn't exist or has not been configured yet.

Overrides MediaSourceBase::getSourceFieldDefinition

1 call to VideoEmbedField::getSourceFieldDefinition()
VideoEmbedField::getVideoUrl in modules/video_embed_media/src/Plugin/media/Source/VideoEmbedField.php
Get the video URL from a media entity.

File

modules/video_embed_media/src/Plugin/media/Source/VideoEmbedField.php, line 184

Class

VideoEmbedField
Provides media source plugin for video embed field.

Namespace

Drupal\video_embed_media\Plugin\media\Source

Code

public function getSourceFieldDefinition(MediaTypeInterface $type) {

  // video_embed_media has not historically had a value in
  // $this->configuration['source_field'], instead just creating
  // field_media_video_embed_field on install and treating that as the source.
  // Here we privilege the standard way, but also allow the old VEM way, of
  // getting the source field's name.
  $field = !empty($this->configuration['source_field']) ? $this->configuration['source_field'] : 'field_media_video_embed_field';
  if ($field) {

    // Be sure that the suggested source field actually exists.
    $fields = $this->entityFieldManager
      ->getFieldDefinitions('media', $type
      ->id());
    return isset($fields[$field]) ? $fields[$field] : NULL;
  }
  return NULL;
}