function DateTimeDatelistWidget::formElement
Same name in other branches
- 8.9.x core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget::formElement()
- 10 core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget::formElement()
- 11.x core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget::formElement()
Overrides DateTimeWidgetBase::formElement
File
-
core/
modules/ datetime/ src/ Plugin/ Field/ FieldWidget/ DateTimeDatelistWidget.php, line 35
Class
- DateTimeDatelistWidget
- Plugin implementation of the 'datetime_datelist' widget.
Namespace
Drupal\datetime\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
// Wrap all of the select elements with a fieldset.
$element['#theme_wrappers'][] = 'fieldset';
$date_order = $this->getSetting('date_order');
if ($this->getFieldSetting('datetime_type') == 'datetime') {
$time_type = $this->getSetting('time_type');
$increment = $this->getSetting('increment');
}
else {
$time_type = '';
$increment = '';
}
// Set up the date part order array.
switch ($date_order) {
case 'YMD':
$date_part_order = [
'year',
'month',
'day',
];
break;
case 'MDY':
$date_part_order = [
'month',
'day',
'year',
];
break;
case 'DMY':
$date_part_order = [
'day',
'month',
'year',
];
break;
}
switch ($time_type) {
case '24':
$date_part_order = array_merge($date_part_order, [
'hour',
'minute',
]);
break;
case '12':
$date_part_order = array_merge($date_part_order, [
'hour',
'minute',
'ampm',
]);
break;
case 'none':
break;
}
$element['value'] = [
'#type' => 'datelist',
'#date_increment' => $increment,
'#date_part_order' => $date_part_order,
] + $element['value'];
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.