public function DateTimeDefaultFormatter::settingsForm

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm 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.

array $form_state: An associative array containing the current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

drupal/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php, line 98
Contains \Drupal\datetime\Plugin\field\formatter\DateTimeDefaultFormatter.

Class

DateTimeDefaultFormatter
Plugin implementation of the 'datetime_default' formatter.

Namespace

Drupal\datetime\Plugin\field\formatter

Code

public function settingsForm(array $form, array &$form_state) {
  $element = array();
  $time = new DrupalDateTime();
  $format_types = system_get_date_formats();
  if (!empty($format_types)) {
    foreach ($format_types as $type => $type_info) {
      $options[$type] = $type_info['name'] . ' (' . format_date($time
        ->format('U'), $type) . ')';
    }
  }
  $elements['format_type'] = array(
    '#type' => 'select',
    '#title' => t('Date format'),
    '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."),
    '#options' => $options,
    '#default_value' => $this
      ->getSetting('format_type'),
  );
  return $elements;
}