You are here

public function TimestampAgoFormatter::settingsForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter::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

core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php, line 107

Class

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

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['future_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Future format'),
    '#default_value' => $this
      ->getSetting('future_format'),
    '#description' => $this
      ->t('Use <em>@interval</em> where you want the formatted interval text to appear.'),
  ];
  $form['past_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Past format'),
    '#default_value' => $this
      ->getSetting('past_format'),
    '#description' => $this
      ->t('Use <em>@interval</em> where you want the formatted interval text to appear.'),
  ];
  $form['granularity'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Granularity'),
    '#description' => $this
      ->t('How many time interval units should be shown in the formatted output.'),
    '#default_value' => $this
      ->getSetting('granularity') ?: 2,
    '#min' => 1,
    '#max' => 6,
  ];
  return $form;
}