reverted: --- b/core/includes/theme.inc +++ a/core/includes/theme.inc @@ -517,7 +517,7 @@ function template_preprocess_datetime_form(&$variables) { $element = $variables['element']; + $variables['attributes'] = array(); - $variables['attributes'] = $element['#attributes']; if (isset($element['#id'])) { $variables['attributes']['id'] = $element['#id']; } @@ -525,10 +525,6 @@ $variables['attributes']['class'] = (array) $element['#attributes']['class']; } - if (!empty($element['#title'])) { - $variables['title'] = $element['#title']; - } - $variables['content'] = $element; } @@ -545,6 +541,10 @@ function template_preprocess_datetime_wrapper(&$variables) { $element = $variables['element']; + if (!empty($element['#title'])) { + $variables['title'] = $element['#title']; + } + // Suppress error messages. $variables['errors'] = NULL; diff -u b/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php --- b/core/lib/Drupal/Core/Datetime/Element/Datetime.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php @@ -232,6 +232,19 @@ $element['#tree'] = TRUE; + // Visibility and disability states need to be applied to the element as a + // whole, but the other states apply to the individual parts. + if (isset($element['#states']) && is_array($element['#states'])) { + $wrapper_states = array_filter($element['#states'], function ($key) { + return in_array($key, ['visible', 'invisible', 'disabled', 'enabled']); + }, ARRAY_FILTER_USE_KEY); + $children_states = array_diff_key($element['#states'], $wrapper_states); + } + else { + $wrapper_states = $children_states = []; + } + $element['#states'] = $wrapper_states; + if ($element['#date_date_element'] != 'none') { $date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : ''; @@ -269,6 +282,7 @@ '#size' => max(12, strlen($element['#value']['date'])), '#error_no_message' => TRUE, '#date_date_format' => $element['#date_date_format'], + '#states' => $children_states, ); // Allows custom callbacks to alter the element. @@ -301,6 +315,7 @@ '#required' => $element['#required'], '#size' => 12, '#error_no_message' => TRUE, + '#states' => $children_states, ); // Allows custom callbacks to alter the element. @@ -313,9 +328,6 @@ } } - // Make sure that the datetime element keeps the #states property. - $element['#states'] = isset($element['#states']) ? $element['#states'] : []; - return $element; } reverted: --- b/core/themes/classy/templates/form/datetime-form.html.twig +++ a/core/themes/classy/templates/form/datetime-form.html.twig @@ -6,29 +6,10 @@ * Available variables: * - attributes: HTML attributes for the datetime form element. * - content: The datelist form element to be output. - * - title: The title of the form element. - * - title_attributes: HTML attributes for the title wrapper. * * @see template_preprocess_datetime_form() */ #} + -{% - set title_classes = [ - 'label', - required ? 'js-form-required', - required ? 'form-required', - ] -%} -{% - set container_classes = [ - 'js-form-wrapper', - 'form-wrapper', - 'container-inline' - ] -%} - - {% if title %} - {{ title }} - {% endif %} {{ content }} diff -u b/core/themes/classy/templates/form/datetime-wrapper.html.twig b/core/themes/classy/templates/form/datetime-wrapper.html.twig --- b/core/themes/classy/templates/form/datetime-wrapper.html.twig +++ b/core/themes/classy/templates/form/datetime-wrapper.html.twig @@ -8,15 +8,35 @@ + * - title: The title of the form element. + * - title_attributes: HTML attributes for the title wrapper. * - description: Description text for the form element. * - required: An indicator for whether the associated form element is required. * * @see template_preprocess_datetime_wrapper() */ #} -{{ content }} -{% if errors %} -
- {{ errors }} -
-{% endif %} -{% if description %} -
{{ description }}
-{% endif %} +{% + set container_classes = [ + 'js-form-wrapper', + 'form-wrapper', + ] +%} +{% + set title_classes = [ + 'label', + required ? 'js-form-required', + required ? 'form-required', + ] +%} + + {% if title %} + {{ title }} + {% endif %} + {{ content }} + {% if errors %} +
+ {{ errors }} +
+ {% endif %} + {% if description %} +
{{ description }}
+ {% endif %} + only in patch2: unchanged: --- a/core/misc/states.js +++ b/core/misc/states.js @@ -609,13 +609,21 @@ if (e.value) { var label = 'label' + (e.target.id ? '[for=' + e.target.id + ']' : ''); var $label = $(e.target).attr({'required': 'required', 'aria-required': 'aria-required'}).closest('.js-form-item, .js-form-wrapper').find(label); + // A complex form element like 'datetime' (one made up of multiple + // sub-elements) may have a label for the element as a whole, which will + // not be a true