You are here

public function MediaSourceBase::buildConfigurationForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::buildConfigurationForm()
  2. 9 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::buildConfigurationForm()
1 method overrides MediaSourceBase::buildConfigurationForm()
OEmbed::buildConfigurationForm in core/modules/media/src/Plugin/media/Source/OEmbed.php
Form constructor.

File

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

Class

MediaSourceBase
Base implementation of media source plugin.

Namespace

Drupal\media

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $options = $this
    ->getSourceFieldOptions();
  $form['source_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Field with source information'),
    '#default_value' => $this->configuration['source_field'],
    '#empty_option' => $this
      ->t('- Create -'),
    '#options' => $options,
    '#description' => $this
      ->t('Select the field that will store essential information about the media item. If "Create" is selected a new field will be automatically created.'),
  ];
  if (!$options && $form_state
    ->get('operation') === 'add') {
    $form['source_field']['#access'] = FALSE;
    $field_definition = $this->fieldTypeManager
      ->getDefinition(reset($this->pluginDefinition['allowed_field_types']));
    $form['source_field_message'] = [
      '#markup' => $this
        ->t('%field_type field will be automatically created on this type to store the essential information about the media item.', [
        '%field_type' => $field_definition['label'],
      ]),
    ];
  }
  elseif ($form_state
    ->get('operation') === 'edit') {
    $form['source_field']['#access'] = FALSE;
    $fields = $this->entityFieldManager
      ->getFieldDefinitions('media', $form_state
      ->get('type')
      ->id());
    $form['source_field_message'] = [
      '#markup' => $this
        ->t('%field_name field is used to store the essential information about the media item.', [
        '%field_name' => $fields[$this->configuration['source_field']]
          ->getLabel(),
      ]),
    ];
  }
  return $form;
}