You are here

public function AgeFieldFormatter::settingsForm in Age Field Formatter 3.0.x

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. 8 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 77

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'),
    '#attributes' => array(
      'class' => array(
        'age-format-select',
      ),
    ),
  ];
  $elements['year_suffix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display a “years” suffix after the age'),
    '#default_value' => $this
      ->getSetting('year_suffix'),
  ];
  $elements['date_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Date/time format'),
    '#description' => $this
      ->t('See <a href="http://php.net/manual/function.date.php" target="_blank">the documentation for PHP date formats</a>.'),
    '#default_value' => $this
      ->getSetting('date_format'),
    '#attributes' => array(
      'class' => array(
        'date-format',
      ),
    ),
  ];
  return $elements;
}