You are here

public function RangeFormatterBase::settingsForm in Range 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

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

File

src/Plugin/Field/FieldFormatter/RangeFormatterBase.php, line 33

Class

RangeFormatterBase
Parent plugin for decimal and integer range formatters.

Namespace

Drupal\range\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['range_separator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Range separator'),
    '#default_value' => $this
      ->getSetting('range_separator'),
    '#weight' => 0,
  ];
  $elements['range_combine'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Combine equivalent values'),
    '#description' => $this
      ->t('If the FROM and TO values are equal, combine the display into a single value.'),
    '#default_value' => $this
      ->getSetting('range_combine'),
    '#weight' => 50,
  ];
  $elements['field_prefix_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display <em>FIELD value</em> prefix and suffix'),
    '#default_value' => $this
      ->getSetting('field_prefix_suffix'),
    '#weight' => 55,
  ];
  $elements['from_prefix_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display <em>FROM value</em> prefix and suffix'),
    '#default_value' => $this
      ->getSetting('from_prefix_suffix'),
    '#weight' => 60,
  ];
  $elements['to_prefix_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display <em>TO value</em> prefix and suffix'),
    '#default_value' => $this
      ->getSetting('to_prefix_suffix'),
    '#weight' => 65,
  ];
  $elements['combined_prefix_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display <em>COMBINED value</em> prefix and suffix'),
    '#default_value' => $this
      ->getSetting('combined_prefix_suffix'),
    '#weight' => 70,
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][range_combine]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $elements;
}