You are here

public function FieldFormatterBase::settingsForm in (Entity Reference) Field Formatters 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::settingsForm()
  2. 3.x src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::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

2 calls to FieldFormatterBase::settingsForm()
FieldFormatterFromViewDisplay::settingsForm in src/Plugin/Field/FieldFormatter/FieldFormatterFromViewDisplay.php
Returns a form to configure settings for the formatter.
FieldFormatterWithInlineSettings::settingsForm in src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php
Returns a form to configure settings for the formatter.
2 methods override FieldFormatterBase::settingsForm()
FieldFormatterFromViewDisplay::settingsForm in src/Plugin/Field/FieldFormatter/FieldFormatterFromViewDisplay.php
Returns a form to configure settings for the formatter.
FieldFormatterWithInlineSettings::settingsForm in src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/FieldFormatterBase.php, line 53

Class

FieldFormatterBase
Base class for field formatters.

Namespace

Drupal\field_formatter\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());
  $form['link_to_entity'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Link to this @entity_label', [
      '@entity_label' => $entity_type
        ->getLabel(),
    ]),
    '#description' => $this
      ->t('Links the field to this (parent) entity (if supported by the field formatter, overriding referenced entity link settings).'),
    '#default_value' => $this
      ->getSetting('link_to_entity'),
  ];
  return $form;
}