function StringFormatter::settingsForm

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  3. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  4. 8.9.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
1 method overrides StringFormatter::settingsForm()
LanguageFormatter::settingsForm in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php

File

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

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());
  $variables = [
    '@entity_label' => $entity_type->getLabel(),
  ];
  if ($entity_type->hasLinkTemplate('canonical')) {
    $form['link_to_entity'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Link to the @entity_label', $variables),
      '#default_value' => $this->getSetting('link_to_entity'),
    ];
    $field_name = $this->fieldDefinition
      ->getName();
    $form['link_rel'] = [
      '#type' => 'radios',
      '#title' => $this->t('Link destination'),
      '#options' => [
        'canonical' => $this->t('Link to view the @entity_label', $variables),
      ],
      // Only show this option when linking to the entity is enabled at all.
'#states' => [
        'visible' => [
          'input[name="fields[' . $field_name . '][settings_edit_form][settings][link_to_entity]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
      '#default_value' => $this->getSetting('link_rel'),
      // No point in showing this option if there's only one link template.
'#access' => FALSE,
    ];
    if ($entity_type->hasLinkTemplate('edit-form')) {
      $form['link_rel']['#options']['edit-form'] = $this->t('Link to edit the @entity_label', $variables);
      $form['link_rel']['#access'] = TRUE;
    }
  }
  return $form;
}

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