You are here

public function FieldTimerCountdownFormatter::settingsForm in Field Timer 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php \Drupal\field_timer\Plugin\Field\FieldFormatter\FieldTimerCountdownFormatter::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 FieldTimerCountdownFormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php, line 111

Class

FieldTimerCountdownFormatter
Plugin implementation of the 'field_timer_countdown' formatter.

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $useSystemLanguageDescription = $this
    ->t('If this option is checked, it will try to ' . 'use appropriate translation from internal files and fallback to the ' . 'site\'s default language or English if nothing is found. Otherwise it ' . 'provides option \'Region\' to configure which translation to use for ' . 'each language on the site.');
  $form['use_system_language'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use system language'),
    '#default_value' => $this
      ->getSetting('use_system_language'),
    '#description' => $useSystemLanguageDescription,
    '#attributes' => [
      'class' => [
        'field-timer-use-system-language',
      ],
    ],
  ];
  $form['regional'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Language'),
    '#default_value' => $this
      ->getSetting('regional'),
    '#options' => $this
      ->languageOptions(),
    '#states' => [
      'invisible' => [
        'input.field-timer-use-system-language' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Format'),
    '#default_value' => $this
      ->getSetting('format'),
    '#description' => $this
      ->t('See <a href=":url" target="_blank">documentation</a> for this parameter.', [
      ':url' => $this
        ->getDocumentationLink([
        'fragment' => 'format',
      ]),
    ]),
  ];
  $form['layout'] = [
    '#type' => 'textarea',
    '#rows' => 3,
    '#cols' => 60,
    '#title' => $this
      ->t('Layout'),
    '#default_value' => $this
      ->getSetting('layout'),
    '#description' => $this
      ->t('See <a href=":url" target="_blank">documentation</a> for this parameter.', [
      ':url' => $this
        ->getDocumentationLink([
        'fragment' => 'layout',
      ]),
    ]),
  ];
  $form['compact'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display in compact format'),
    '#default_value' => $this
      ->getSetting('compact'),
  ];
  $form['significant'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Granularity'),
    '#options' => range(0, 7),
    '#default_value' => $this
      ->getSetting('significant'),
  ];
  $form['timeSeparator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Time separator'),
    '#default_value' => $this
      ->getSetting('timeSeparator'),
  ];
  $form['padZeroes'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Pad with zeroes'),
    '#default_value' => $this
      ->getSetting('padZeroes'),
  ];
  return $form;
}