You are here

public function TimeFieldFormatter::settingsForm in Time Formatter 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/TimeFieldFormatter.php \Drupal\time_formatter\Plugin\Field\FieldFormatter\TimeFieldFormatter::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/TimeFieldFormatter.php, line 84

Class

TimeFieldFormatter
Plugin implementation of the 'time_field_formatter' formatter.

Namespace

Drupal\time_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  return [
    'storage' => [
      '#type' => 'select',
      '#title' => $this
        ->t('Storage'),
      '#options' => [
        self::STORAGE_SECONDS => $this
          ->t('Seconds'),
        self::STORAGE_MILLISECONDS => $this
          ->t('Milliseconds'),
      ],
      '#default_value' => $this
        ->getSetting('storage'),
    ],
    'display' => [
      '#type' => 'select',
      '#title' => $this
        ->t('Display'),
      '#options' => [
        self::DISPLAY_HMSMS => $this
          ->t('123h 59m 59s 999ms'),
        self::DISPLAY_HMS => $this
          ->t('123h 59m 59s'),
        self::DISPLAY_NUMBERSMS => $this
          ->t('123:59:59.999'),
        self::DISPLAY_NUMBERS => $this
          ->t('123:59:59'),
      ],
      '#default_value' => $this
        ->getSetting('display'),
    ],
    'hours' => [
      '#type' => 'select',
      '#title' => $this
        ->t('Display hours'),
      '#options' => [
        self::HOURS_ALWAYS => $this
          ->t('Always'),
        self::HOURS_OPTIONAL => $this
          ->t('Optional'),
        self::HOURS_NEVER => $this
          ->t('Never'),
      ],
      '#default_value' => $this
        ->getSetting('hours'),
    ],
  ] + parent::settingsForm($form, $form_state);
}