You are here

public function Video::settingsForm in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/Video.php \Drupal\video_embed_field\Plugin\Field\FieldFormatter\Video::settingsForm()

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/Video.php, line 136

Class

Video
Plugin implementation of the video field formatter.

Namespace

Drupal\video_embed_field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['autoplay'] = [
    '#title' => $this
      ->t('Autoplay'),
    '#type' => 'checkbox',
    '#description' => $this
      ->t('Autoplay the videos for users without the "never autoplay videos" permission. Roles with this permission will bypass this setting.'),
    '#default_value' => $this
      ->getSetting('autoplay'),
  ];
  $elements['responsive'] = [
    '#title' => $this
      ->t('Responsive Video'),
    '#type' => 'checkbox',
    '#description' => $this
      ->t("Make the video fill the width of it's container, adjusting to the size of the user's screen."),
    '#default_value' => $this
      ->getSetting('responsive'),
  ];

  // Loosely match the name attribute so forms which don't have a field
  // formatter structure (such as the WYSIWYG settings form) are also matched.
  $responsive_checked_state = [
    'visible' => [
      [
        ':input[name*="responsive"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $elements['width'] = [
    '#title' => $this
      ->t('Width'),
    '#type' => 'number',
    '#field_suffix' => 'px',
    '#default_value' => $this
      ->getSetting('width'),
    '#required' => TRUE,
    '#size' => 20,
    '#states' => $responsive_checked_state,
  ];
  $elements['height'] = [
    '#title' => $this
      ->t('Height'),
    '#type' => 'number',
    '#field_suffix' => 'px',
    '#default_value' => $this
      ->getSetting('height'),
    '#required' => TRUE,
    '#size' => 20,
    '#states' => $responsive_checked_state,
  ];
  return $elements;
}