You are here

protected function MediaSourceBase::getSourceFieldOptions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldOptions()

Get the source field options for the media type form.

This returns all fields related to media entities, filtered by the allowed field types in the media source annotation.

Return value

string[] A list of source field options for the media type form.

1 call to MediaSourceBase::getSourceFieldOptions()
MediaSourceBase::buildConfigurationForm in core/modules/media/src/MediaSourceBase.php
Form constructor.

File

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

Class

MediaSourceBase
Base implementation of media source plugin.

Namespace

Drupal\media

Code

protected function getSourceFieldOptions() {

  // If there are existing fields to choose from, allow the user to reuse one.
  $options = [];
  foreach ($this->entityFieldManager
    ->getFieldStorageDefinitions('media') as $field_name => $field) {
    $allowed_type = in_array($field
      ->getType(), $this->pluginDefinition['allowed_field_types'], TRUE);
    if ($allowed_type && !$field
      ->isBaseField()) {
      $options[$field_name] = $field
        ->getLabel();
    }
  }
  return $options;
}