function OEmbedFormatter::settingsForm

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

Overrides FormatterBase::settingsForm

File

core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php, line 262

Class

OEmbedFormatter
Plugin implementation of the 'oembed' formatter.

Namespace

Drupal\media\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form, $form_state) + [
        'max_width' => [
            '#type' => 'number',
            '#title' => $this->t('Maximum width'),
            '#default_value' => $this->getSetting('max_width'),
            '#size' => 5,
            '#maxlength' => 5,
            '#field_suffix' => $this->t('pixels'),
            '#min' => 0,
        ],
        'max_height' => [
            '#type' => 'number',
            '#title' => $this->t('Maximum height'),
            '#default_value' => $this->getSetting('max_height'),
            '#size' => 5,
            '#maxlength' => 5,
            '#field_suffix' => $this->t('pixels'),
            '#min' => 0,
        ],
        'loading' => [
            '#type' => 'details',
            '#title' => $this->t('oEmbed loading'),
            '#description' => $this->t('Lazy render oEmbed with native loading attribute (<em>loading="lazy"</em>). This improves performance by allowing browsers to lazily load assets.'),
            'attribute' => [
                '#title' => $this->t('oEmbed loading attribute'),
                '#type' => 'radios',
                '#default_value' => $this->getSetting('loading')['attribute'],
                '#options' => [
                    'lazy' => $this->t('Lazy (<em>loading="lazy"</em>)'),
                    'eager' => $this->t('Eager (<em>loading="eager"</em>)'),
                ],
                '#description' => $this->t('Select the loading attribute for oEmbed. <a href=":link">Learn more about the loading attribute for oEmbed.</a>', [
                    ':link' => 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attributes',
                ]),
            ],
        ],
    ];
    $form['loading']['attribute']['lazy']['#description'] = $this->t('Delays loading the resource until that section of the page is visible in the browser. When in doubt, lazy loading is recommended.');
    $form['loading']['attribute']['eager']['#description'] = $this->t('Force browsers to download a resource as soon as possible. This is the browser default for legacy reasons. Only use this option when the resource is always expected to render.');
    return $form;
}

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