function TimestampAgoFormatter::settingsForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter::settingsForm()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter::settingsForm()
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter::settingsForm()

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'),
        '#required' => TRUE,
        '#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'),
        '#required' => TRUE,
        '#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' => 7,
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.