diff --git a/core/includes/form.inc b/core/includes/form.inc index 540966c..9b4eb4f 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -233,6 +233,8 @@ function template_preprocess_fieldset(&$variables) { */ function template_preprocess_details(&$variables) { $element = $variables['element']; + Element::setAttributes($element, array('id')); + Element\RenderElement::setAttributes($element); $variables['attributes'] = $element['#attributes']; $variables['summary_attributes'] = new Attribute(); if (!empty($element['#title'])) { @@ -247,12 +249,13 @@ function template_preprocess_details(&$variables) { if (!empty($element['#description'])) { $variables['description_display'] = isset($element['#description_display']) ? $element['#description_display'] : 'before'; - $description_attributes = []; - if (!empty($element['#id'])) { - $description_attributes['id'] = $element['#id'] . '--description'; - } + $description_id = $element['#attributes']['id'] . '--description'; + $description_attributes['id'] = $description_id; $variables['description']['attributes'] = new Attribute($description_attributes); $variables['description']['content'] = $element['#description']; + + // Add the description's id to the fieldset aria attributes. + $variables['attributes']['aria-describedby'] = $description_id; } $variables['children'] = (isset($element['#children'])) ? $element['#children'] : ''; diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index cb66445..c901c9c 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -908,7 +908,6 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state '#required' => FALSE, '#attributes' => array(), '#title_display' => 'before', - '#description_display' => 'after', '#description_display' => (isset($element['#type']) && $element['#type'] == 'details') ? 'before' : 'after', '#errors' => NULL, ); diff --git a/core/themes/stable/templates/form/details.html.twig b/core/themes/stable/templates/form/details.html.twig index f4c99e1..76e8c0f 100644 --- a/core/themes/stable/templates/form/details.html.twig +++ b/core/themes/stable/templates/form/details.html.twig @@ -25,7 +25,7 @@ {% endif %} - {{ description }} + {{ description.content }} {{ children }} {{ value }}