You are here

public function StringFormatter::settingsForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::settingsForm()
  2. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter::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

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 93

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;
}