You are here

public function TimestampFormatter::settingsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter::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/TimestampFormatter.php, line 108
Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter.

Class

TimestampFormatter
Plugin implementation of the 'timestamp' formatter.

Namespace

Drupal\Core\Field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $date_formats = array();
  foreach ($this->dateFormatStorage
    ->loadMultiple() as $machine_name => $value) {
    $date_formats[$machine_name] = $this
      ->t('@name format: @date', array(
      '@name' => $value
        ->label(),
      '@date' => $this->dateFormatter
        ->format(REQUEST_TIME, $machine_name),
    ));
  }
  $date_formats['custom'] = $this
    ->t('Custom');
  $elements['date_format'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Date format'),
    '#options' => $date_formats,
    '#default_value' => $this
      ->getSetting('date_format') ?: 'medium',
  );
  $elements['custom_date_format'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Custom date format'),
    '#description' => $this
      ->t('See <a href=":url" target="_blank">the documentation for PHP date formats</a>.', [
      ':url' => 'http://php.net/manual/function.date.php',
    ]),
    '#default_value' => $this
      ->getSetting('custom_date_format') ?: '',
  );
  $elements['custom_date_format']['#states']['visible'][] = array(
    ':input[name="options[settings][date_format]"]' => array(
      'value' => 'custom',
    ),
  );
  $elements['timezone'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Time zone'),
    '#options' => array(
      '' => $this
        ->t('- Default site/user time zone -'),
    ) + system_time_zones(FALSE),
    '#default_value' => $this
      ->getSetting('timezone'),
  );
  return $elements;
}