You are here

public function KeyValueFormatter::settingsForm in Key value field 8

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

File

src/Plugin/Field/FieldFormatter/KeyValueFormatter.php, line 38

Class

KeyValueFormatter
Plugin implementation of the 'key_value' formatter.

Namespace

Drupal\key_value_field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {

  // Get the default textfield form.
  $form = parent::settingsForm($form, $form_state);

  // Allow the formatter to hide the key.
  $form['value_only'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Value only'),
    '#default_value' => $this
      ->getSetting('value_only'),
    '#description' => $this
      ->t('Make the formatter hide the "Key" part of the field and display the "Value" only.'),
    '#weight' => 4,
  ];
  return $form;
}