public function DateRangeFormatterRangeFormatter::settingsForm in Date range formatter 8.3
Same name and namespace in other branches
- 9.0.x src/Plugin/Field/FieldFormatter/DateRangeFormatterRangeFormatter.php \Drupal\date_range_formatter\Plugin\Field\FieldFormatter\DateRangeFormatterRangeFormatter::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 DateTimeCustomFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ DateRangeFormatterRangeFormatter.php, line 88
Class
- DateRangeFormatterRangeFormatter
- Plugin implementation of the 'Custom' formatter for 'daterange' fields.
Namespace
Drupal\date_range_formatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
unset($form['date_format']);
$form['single'] = [
'#type' => 'textfield',
'#title' => t('Date format for single date'),
'#default_value' => $this
->getSetting('single') ?: 'd F Y',
];
$form['single_all_day'] = [
'#type' => 'textfield',
'#title' => t('Date format for the single date if the date is "all day"'),
'#default_value' => $this
->getSetting('single_all_day') ?: 'd F Y',
];
$form['one_day'] = [
'#type' => 'textfield',
'#title' => t('Date format for the single day date range'),
'#default_value' => $this
->getSetting('one_day') ?: 'd F Y',
];
$form['one_month'] = [
'#type' => 'textfield',
'#title' => t('Date format for the single month date range'),
'#default_value' => $this
->getSetting('one_month') ?: 'd - {d} F Y',
];
$form['several_months'] = [
'#type' => 'textfield',
'#title' => t('Date format for the single year date range'),
'#default_value' => $this
->getSetting('several_months') ?: 'd F - {d} {F} Y',
];
$form['several_years'] = [
'#type' => 'textfield',
'#title' => t('Date format for multiple years date range'),
'#default_value' => $this
->getSetting('several_years') ?: 'd F Y - {d} {F} {Y}',
];
$form['help'] = [
'#type' => 'markup',
'#markup' => t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', [
'@url' => 'http://php.net/manual/function.date.php',
]) . '<br />' . t('Use letters in braces for end date elements, for example, {d} means the day of the end date.') . '<br />' . t('These format values are translated, for example, t("d F Y") instead of "d F Y" will be used as the actual date format.'),
];
return $form;
}