You are here

public function MediaEmbed::settingsForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()

Generates a filter's settings form.

Parameters

array $form: A minimally prepopulated form array.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the (entire) configuration form.

Return value

array The $form array with additional form elements for the settings of this filter. The submitted form values should match $this->settings.

Overrides FilterBase::settingsForm

File

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

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