function DateTimeDefaultFormatter::settingsForm
Same name in other branches
- 9 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter::settingsForm()
- 8.9.x core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter::settingsForm()
- 10 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter::settingsForm()
Overrides DateTimeFormatterBase::settingsForm
1 call to DateTimeDefaultFormatter::settingsForm()
- DateRangeDefaultFormatter::settingsForm in core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldFormatter/ DateRangeDefaultFormatter.php
1 method overrides DateTimeDefaultFormatter::settingsForm()
- DateRangeDefaultFormatter::settingsForm in core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldFormatter/ DateRangeDefaultFormatter.php
File
-
core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimeDefaultFormatter.php, line 43
Class
- DateTimeDefaultFormatter
- Plugin implementation of the 'Default' formatter for 'datetime' fields.
Namespace
Drupal\datetime\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$time = new DrupalDateTime();
$format_types = $this->dateFormatStorage
->loadMultiple();
$options = [];
foreach ($format_types as $type => $type_info) {
$format = $this->dateFormatter
->format($time->getTimestamp(), $type);
$options[$type] = $type_info->label() . ' (' . $format . ')';
}
$form['format_type'] = [
'#type' => 'select',
'#title' => $this->t('Date format'),
'#description' => $this->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 $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.