Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MediaSourceBase.php

function MediaSourceBase::buildConfigurationForm

Overrides PluginFormInterface::buildConfigurationForm

2 calls to MediaSourceBase::buildConfigurationForm()
OEmbed::buildConfigurationForm in core/modules/media/src/Plugin/media/Source/OEmbed.php
Form constructor.
OEmbed::buildConfigurationForm in core/modules/media/src/Plugin/media/Source/OEmbed.php
Form constructor.
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 175

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal