diff --git a/core/includes/theme.inc b/core/includes/theme.inc index f180cbd..d187423 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -576,8 +576,14 @@ function template_preprocess_datetime_wrapper(&$variables) { // Suppress error messages. $variables['errors'] = NULL; + $variables['description'] = NULL; if (!empty($element['#description'])) { - $variables['description'] = $element['#description']; + $description_attributes = []; + if (!empty($element['#id'])) { + $description_attributes['id'] = $element['#id'] . '--description'; + } + $variables['description']['attributes'] = new Attribute($description_attributes); + $variables['description']['content'] = $element['#description']; } $variables['required'] = FALSE; diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php index 8cdabf1..06ced05 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php @@ -35,6 +35,9 @@ public static function defaultSettings() { 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') { diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php index 89381ab..6d03ffd 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDefaultWidget.php @@ -59,6 +59,16 @@ public static function create(ContainerInterface $container, array $configuratio public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $element = parent::formElement($items, $delta, $element, $form, $form_state); + // If the field is date-only, make sure the title is displayed. Otherwise, + // wrap everything in a fieldset, and the title will be shown in the legend. + if ($this->getFieldSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) { + $element['value']['#title'] = $this->fieldDefinition->getLabel(); + $element['value']['#description'] = $this->fieldDefinition->getDescription(); + } + else { + $element['#theme_wrappers'][] = 'fieldset'; + } + // Identify the type of date and time elements to use. switch ($this->getFieldSetting('datetime_type')) { case DateTimeItem::DATETIME_TYPE_DATE: diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeWidgetBase.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeWidgetBase.php index cc484f3..b363eed 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeWidgetBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeWidgetBase.php @@ -25,16 +25,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#required' => $element['#required'], ); - // If the field is date-only, make sure the title is displayed. Otherwise, - // wrap everything in a fieldset, and the title will be shown in the legend. - if ($this->getFieldSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) { - $element['value']['#title'] = $this->fieldDefinition->getLabel(); - $element['value']['#description'] = $this->fieldDefinition->getDescription(); - } - else { - $element['#theme_wrappers'][] = 'fieldset'; - } - if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) { // A date-only field should have no timezone conversion performed, so // use the same timezone as for storage. diff --git a/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php b/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php index 30cad60..a4f8350 100644 --- a/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php +++ b/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php @@ -20,14 +20,11 @@ class DateRangeWidgetBase extends DateTimeWidgetBase { public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $element = parent::formElement($items, $delta, $element, $form, $form_state); - // Only apply the fieldset wrapper if the parent hasn't already. - if (empty($element['#theme_wrappers']) || !in_array('fieldset', $element['#theme_wrappers'])) { - $element['#theme_wrappers'][] = 'fieldset'; - } + // Wrap all of the select elements with a fieldset. + $element['#theme_wrappers'][] = 'fieldset'; $element['#element_validate'][] = [$this, 'validateStartEnd']; $element['value']['#title'] = $this->t('Start date'); - unset($element['value']['#description']); $element['end_value'] = [ '#title' => $this->t('End date'), diff --git a/core/modules/system/templates/datetime-wrapper.html.twig b/core/modules/system/templates/datetime-wrapper.html.twig index 8430baa..d39df2f 100644 --- a/core/modules/system/templates/datetime-wrapper.html.twig +++ b/core/modules/system/templates/datetime-wrapper.html.twig @@ -30,4 +30,6 @@ {{ errors }} {% endif %} -{{ description }} +{% if description.content %} + {{ description.content }} +{% endif %} diff --git a/core/themes/classy/templates/form/datetime-wrapper.html.twig b/core/themes/classy/templates/form/datetime-wrapper.html.twig index 3f6aa59..a11c1e7 100644 --- a/core/themes/classy/templates/form/datetime-wrapper.html.twig +++ b/core/themes/classy/templates/form/datetime-wrapper.html.twig @@ -29,6 +29,8 @@ {{ errors }} {% endif %} -{% if description %} -
{{ description }}
+{% if description.content %} + + {{ description.content }} + {% endif %} diff --git a/core/themes/stable/templates/form/datetime-wrapper.html.twig b/core/themes/stable/templates/form/datetime-wrapper.html.twig index 3c37ffd..a89bd8d 100644 --- a/core/themes/stable/templates/form/datetime-wrapper.html.twig +++ b/core/themes/stable/templates/form/datetime-wrapper.html.twig @@ -28,4 +28,6 @@ {{ errors }} {% endif %} -{{ description }} +{% if description.content %} + {{ description.content }} +{% endif %}