You are here

public function ApStyleDateRangeFieldFormatter::settingsForm in AP Style Date 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/ApStyleDateRangeFieldFormatter.php, line 103

Class

ApStyleDateRangeFieldFormatter
Plugin implementation of the 'timestamp' formatter as time ago.

Namespace

Drupal\date_ap_style\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['always_display_year'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Always display year'),
    '#description' => $this
      ->t('When unchecked, the year will not be displayed if the date is in the same year as the current date.'),
    '#default_value' => $this
      ->getSetting('always_display_year'),
  ];
  $elements['use_today'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use today'),
    '#default_value' => $this
      ->getSetting('use_today'),
  ];
  $elements['cap_today'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Capitalize today'),
    '#default_value' => $this
      ->getSetting('cap_today'),
  ];
  $elements['display_time'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display time'),
    '#default_value' => $this
      ->getSetting('display_time'),
  ];
  $elements['time_before_date'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display time before date'),
    '#description' => $this
      ->t('When checked, the time will be displayed before the date. Otherwise it will be displayed after the date.'),
    '#default_value' => $this
      ->getSetting('time_before_date'),
    '#states' => [
      'visible' => [
        ':input[name$="[settings][display_time]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['use_all_day'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show "All Day" instead of midnight'),
    '#default_value' => $this
      ->getSetting('use_all_day'),
    '#states' => [
      'visible' => [
        ':input[name$="[settings][display_time]"]' => [
          'checked' => TRUE,
        ],
      ],
      'unchecked' => [
        ':input[name$="[settings][display_noon_and_midnight]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['display_noon_and_midnight'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display noon and midnight'),
    '#default_value' => $this
      ->getSetting('display_noon_and_midnight'),
    '#description' => $this
      ->t('Converts 12:00 p.m. to "noon" and 12:00 a.m. to "midnight".'),
    '#states' => [
      'visible' => [
        ':input[name$="[settings][display_time]"]' => [
          'checked' => TRUE,
        ],
      ],
      'unchecked' => [
        ':input[name$="[settings][use_all_day]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['capitalize_noon_and_midnight'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Capitalize noon and midnight'),
    '#default_value' => $this
      ->getSetting('capitalize_noon_and_midnight'),
    '#states' => [
      'visible' => [
        ':input[name$="[settings][display_time]"]' => [
          'checked' => TRUE,
        ],
        ':input[name$="[settings][display_noon_and_midnight]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['separator'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Date range separator'),
    '#options' => [
      'endash' => $this
        ->t('En dash'),
      'to' => $this
        ->t('to'),
    ],
    '#default_value' => $this
      ->getSetting('separator'),
  ];
  $elements['timezone'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Time zone'),
    '#options' => [
      '' => $this
        ->t('- Default site/user time zone -'),
    ] + system_time_zones(FALSE),
    '#default_value' => $this
      ->getSetting('timezone'),
  ];
  return $elements;
}