function MediaEmbed::settingsForm

Same name in other branches
  1. 9 core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()
  2. 8.9.x core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()
  3. 10 core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()

Overrides FilterBase::settingsForm

File

core/modules/media/src/Plugin/Filter/MediaEmbed.php, line 152

Class

MediaEmbed
Provides a filter to embed media items using a custom tag.

Namespace

Drupal\media\Plugin\Filter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
    $view_mode_options = $this->entityDisplayRepository
        ->getViewModeOptions('media');
    $form['default_view_mode'] = [
        '#type' => 'select',
        '#options' => $view_mode_options,
        '#title' => $this->t('Default view mode'),
        '#default_value' => $this->settings['default_view_mode'],
        '#description' => $this->t('The view mode that an embedded media item should be displayed in by default. This can be overridden using the <code>data-view-mode</code> attribute.'),
    ];
    $bundles = $this->entityTypeBundleInfo
        ->getBundleInfo('media');
    $bundle_options = array_map(function ($item) {
        return $item['label'];
    }, $bundles);
    $form['allowed_media_types'] = [
        '#title' => $this->t('Media types selectable in the Media Library'),
        '#type' => 'checkboxes',
        '#options' => $bundle_options,
        '#default_value' => $this->settings['allowed_media_types'],
        '#description' => $this->t('If none are selected, all will be allowed.'),
        '#element_validate' => [
            [
                static::class,
                'validateOptions',
            ],
        ],
    ];
    $form['allowed_view_modes'] = [
        '#title' => $this->t("View modes selectable in the 'Edit media' dialog"),
        '#type' => 'checkboxes',
        '#options' => $view_mode_options,
        '#default_value' => $this->settings['allowed_view_modes'],
        '#description' => $this->t("If two or more view modes are selected, users will be able to update the view mode that an embedded media item should be displayed in after it has been embedded.  If less than two view modes are selected, media will be embedded using the default view mode and no view mode options will appear after a media item has been embedded."),
        '#element_validate' => [
            [
                static::class,
                'validateOptions',
            ],
        ],
    ];
    return $form;
}

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