function StringFormatter::settingsForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()

Overrides FormatterBase::settingsForm

1 call to StringFormatter::settingsForm()
LanguageFormatter::settingsForm in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php
Returns a form to configure settings for the formatter.
1 method overrides StringFormatter::settingsForm()
LanguageFormatter::settingsForm in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php
Returns a form to configure settings for the formatter.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php, line 91

Class

StringFormatter
Plugin implementation of the 'string' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form, $form_state);
    $entity_type = $this->entityTypeManager
        ->getDefinition($this->fieldDefinition
        ->getTargetEntityTypeId());
    if ($entity_type->hasLinkTemplate('canonical')) {
        $form['link_to_entity'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Link to the @entity_label', [
                '@entity_label' => $entity_type->getLabel(),
            ]),
            '#default_value' => $this->getSetting('link_to_entity'),
        ];
    }
    return $form;
}

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