You are here

public function AgeFieldFormatter::settingsForm in Age Field Formatter 8

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

File

src/Plugin/Field/FieldFormatter/AgeFieldFormatter.php, line 39

Class

AgeFieldFormatter
Plugin implementation of the 'age_field_formatter' formatter.

Namespace

Drupal\age_field_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $age_formats = [
    'birthdate' => $this
      ->t('Date plus Age with label'),
    'birthdate_nolabel' => $this
      ->t('Date with no Age label'),
    'age_only' => $this
      ->t('Age only'),
  ];
  $elements['age_format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Date/age format'),
    '#options' => $age_formats,
    '#default_value' => $this
      ->getSetting('age_format'),
  ];
  $elements['year_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display a “years” suffix after the age'),
    '#default_value' => $this
      ->getSetting('year_suffix'),
  ];
  return $elements;
}