diff --git a/core/includes/form.inc b/core/includes/form.inc index 15ef023..9865e2f 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -241,7 +241,7 @@ function template_preprocess_fieldset(&$variables) { function template_preprocess_details(&$variables) { $element = $variables['element']; Element::setAttributes($element, ['id']); - Element\RenderElement::setAttributes($element); + RenderElement::setAttributes($element); $variables['attributes'] = $element['#attributes']; $variables['summary_attributes'] = new Attribute(); if (!empty($element['#title'])) { diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 2c36a22..c4a1fd2 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -901,12 +901,11 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state $element['#defaults_loaded'] = TRUE; } // Assign basic defaults common for all form elements. - // Note that #description_display is below by default, except for details. $element += [ '#required' => FALSE, '#attributes' => [], '#title_display' => 'before', - '#description_display' => (isset($element['#type']) && $element['#type'] == 'details') ? 'before' : 'after', + '#description_display' => 'after', '#errors' => NULL, ]; diff --git a/core/lib/Drupal/Core/Render/Element/Details.php b/core/lib/Drupal/Core/Render/Element/Details.php index 92bbb32..fb3e74c 100644 --- a/core/lib/Drupal/Core/Render/Element/Details.php +++ b/core/lib/Drupal/Core/Render/Element/Details.php @@ -44,6 +44,7 @@ public function getInfo() { return [ '#open' => FALSE, '#value' => NULL, + '#description_display' => 'before', '#process' => [ [$class, 'processGroup'], [$class, 'processAjaxForm'], diff --git a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php index 01254a8..549e8e4 100644 --- a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php +++ b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php @@ -107,19 +107,19 @@ public function testFormDescriptions() { $field_id = 'edit-form-textfield-test-description-default'; $description_id = $field_id . '--description'; $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[@id="' . $description_id . '"]'); - $this->assertTrue(isset($elements[0]), 'Properly places by default the #description element after the form item.'); + $this->assertTrue(isset($elements[0]), t('Properly places by default the #description element after the form item.')); // Check #description placement with #description_display='after'. $field_id = 'edit-form-textfield-test-description-after'; $description_id = $field_id . '--description'; $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[@id="' . $description_id . '"]'); - $this->assertTrue(isset($elements[0]), 'Properly places the #description element after the form item.'); + $this->assertTrue(isset($elements[0]), t('Properly places the #description element after the form item.')); // Check #description placement with #description_display='before'. $field_id = 'edit-form-textfield-test-description-before'; $description_id = $field_id . '--description'; $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/preceding-sibling::div[@id="' . $description_id . '"]'); - $this->assertTrue(isset($elements[0]), 'Properly places the #description element before the form item.'); + $this->assertTrue(isset($elements[0]), t('Properly places the #description element before the form item.')); // Check if the class is 'visually-hidden' on the form element description // for the option with #description_display='invisible' and also check that @@ -127,7 +127,38 @@ public function testFormDescriptions() { $field_id = 'edit-form-textfield-test-description-invisible'; $description_id = $field_id . '--description'; $elements = $this->xpath('//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[contains(@class, "visually-hidden")]'); - $this->assertTrue(isset($elements[0]), 'Properly renders the #description element visually-hidden.'); + $this->assertTrue(isset($elements[0]), t('Properly renders the #description element visually-hidden.')); + + + $this->drupalGet('form-test/group-details'); + + // Check #description default placement in a 'details' element. + $field_id = 'edit-meta'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div/preceding-sibling::div'); + $this->assertTrue(isset($elements[0]), 'Properly places by default the #description element before the form item within details group.'); + + // Check #description placement with #description_display='before' in a + // 'details' element. + $field_id = 'edit-details-before'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-before"]/preceding-sibling::div[@id="' . $description_id . '"]'); + $this->assertTrue(isset($elements[0]), 'Properly places the #description element before the form item within details group.'); + + // Check #description placement with #description_display='after' in a + // 'details' element. + $field_id = 'edit-details-after'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-after"]/following-sibling::div[@id="' . $description_id . '"]'); + $this->assertTrue(isset($elements[0]), 'Properly places the #description element after the form item within details group.'); + + // Check if the class is 'visually-hidden' on the form details description + // for the option with #description_display='invisible' and also check that + // the description is placed after the form element. + $field_id = 'edit-details-invisible'; + $description_id = $field_id . '--description'; + $elements = $this->xpath('//details[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]//div[@id="edit-meta-invisible"]/following-sibling::div[contains(@class, "visually-hidden")]'); + $this->assertTrue(isset($elements[0]), 'Properly renders the #description element visually-hidden within details group.'); } /** diff --git a/core/themes/stable/templates/form/details.html.twig b/core/themes/stable/templates/form/details.html.twig index 0484677..ccd2796 100644 --- a/core/themes/stable/templates/form/details.html.twig +++ b/core/themes/stable/templates/form/details.html.twig @@ -31,7 +31,7 @@ {% endif %} - {{ description.content }} + {{ description }} {{ children }} {{ value }}