function LinkFormatter::settingsForm

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

Overrides FormatterBase::settingsForm

File

core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php, line 92

Class

LinkFormatter
Plugin implementation of the 'link' formatter.

Namespace

Drupal\link\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
    $elements = parent::settingsForm($form, $form_state);
    $elements['trim_length'] = [
        '#type' => 'number',
        '#title' => $this->t('Trim link text length'),
        '#field_suffix' => $this->t('characters'),
        '#default_value' => $this->getSetting('trim_length'),
        '#min' => 1,
        '#description' => $this->t('Leave blank to allow unlimited link text lengths.'),
    ];
    $elements['url_only'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('URL only'),
        '#default_value' => $this->getSetting('url_only'),
        '#access' => $this->getPluginId() == 'link',
    ];
    $elements['url_plain'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Show URL as plain text'),
        '#default_value' => $this->getSetting('url_plain'),
        '#access' => $this->getPluginId() == 'link',
        '#states' => [
            'visible' => [
                ':input[name*="url_only"]' => [
                    'checked' => TRUE,
                ],
            ],
        ],
    ];
    $elements['rel'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Add rel="nofollow" to links'),
        '#return_value' => 'nofollow',
        '#default_value' => $this->getSetting('rel'),
    ];
    $elements['target'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Open link in new window'),
        '#return_value' => '_blank',
        '#default_value' => $this->getSetting('target'),
    ];
    return $elements;
}

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