+ {% if description_display == 'before' and description.content %}
+
+ {{ description.content }}
+
+ {% endif %}
{% if errors %}
{{ errors }}
@@ -56,7 +67,7 @@
{% if suffix %}
{{ suffix }}
{% endif %}
- {% if description.content %}
+ {% if description_display in ['after', 'invisible'] and description.content %}
{{ description.content }}
{% endif %}
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupFieldsetForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupFieldsetForm.php
index fd7d83b..d16a452 100644
--- a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupFieldsetForm.php
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupFieldsetForm.php
@@ -21,20 +21,69 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $required = FALSE) {
- $form['fieldset'] = array(
+ $form['fieldset'] = [
'#type' => 'fieldset',
'#title' => 'Fieldset',
'#required' => !empty($required),
- );
- $form['meta'] = array(
+ ];
+ $form['meta'] = [
'#type' => 'container',
'#title' => 'Group element',
'#group' => 'fieldset',
- );
- $form['meta']['element'] = array(
+ ];
+ $form['meta']['element'] = [
'#type' => 'textfield',
'#title' => 'Nest in container element',
- );
+ ];
+
+ $form['fieldset_before'] = [
+ '#type' => 'fieldset',
+ '#title' => 'Fieldset test for description before element',
+ '#description' => 'Fieldset test for description before element.',
+ '#description_display' => 'before',
+ ];
+ $form['meta_before'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'fieldset_before',
+ ];
+ $form['meta_before']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
+ $form['fieldset_after'] = [
+ '#type' => 'fieldset',
+ '#title' => 'Fieldset test for description after element',
+ '#description' => 'Fieldset test for description after element.',
+ '#description_display' => 'after',
+ ];
+ $form['meta_after'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'fieldset_after',
+ ];
+ $form['meta_after']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
+ $form['fieldset_invisible'] = [
+ '#type' => 'fieldset',
+ '#title' => 'Fieldset test for visually-hidden description',
+ '#description' => 'Fieldset test for visually-hidden description.',
+ '#description_display' => 'invisible',
+ ];
+ $form['meta_invisible'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'fieldset_invisible',
+ ];
+ $form['meta_invisible']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
return $form;
}
diff --git a/core/themes/classy/templates/form/fieldset.html.twig b/core/themes/classy/templates/form/fieldset.html.twig
index 0d089ed..03b3189 100644
--- a/core/themes/classy/templates/form/fieldset.html.twig
+++ b/core/themes/classy/templates/form/fieldset.html.twig
@@ -13,6 +13,12 @@
* - description: The description element containing the following properties:
* - content: The description content of the fieldset.
* - attributes: HTML attributes to apply to the description container.
+ * - description_display: Description display setting. It can have these values:
+ * - before: The description is output before the element.
+ * - after: The description is output after the element. This is the default
+ * value.
+ * - invisible: The description is output after the element, hidden visually
+ * but available to screen readers.
* - children: The rendered child elements of the fieldset.
* - prefix: The content to add before the fieldset children.
* - suffix: The content to add after the fieldset children.
@@ -41,6 +47,11 @@
{{ legend.title }}
+ {% if description_display == 'before' and description.content %}
+
+ {{ description.content }}
+
+ {% endif %}
{% if errors %}
diff --git a/core/themes/stable/templates/form/fieldset.html.twig b/core/themes/stable/templates/form/fieldset.html.twig
index 8f1f73d..e7a02a8 100644
--- a/core/themes/stable/templates/form/fieldset.html.twig
+++ b/core/themes/stable/templates/form/fieldset.html.twig
@@ -13,6 +13,12 @@
* - description: The description element containing the following properties:
* - content: The description content of the fieldset.
* - attributes: HTML attributes to apply to the description container.
+ * - description_display: Description display setting. It can have these values:
+ * - before: The description is output before the element.
+ * - after: The description is output after the element. This is the default
+ * value.
+ * - invisible: The description is output after the element, hidden visually
+ * but available to screen readers.
* - children: The rendered child elements of the fieldset.
* - prefix: The content to add before the fieldset children.
* - suffix: The content to add after the fieldset children.
@@ -41,6 +47,11 @@
{{ legend.title }}
+ {% if description_display == 'before' and description.content %}
+
+ {{ description.content }}
+
+ {% endif %}
{% if errors %}
{{ errors }}
@@ -53,7 +64,7 @@
{% if suffix %}
{{ suffix }}
{% endif %}
- {% if description.content %}
+ {% if description_display in ['after', 'invisible'] and description.content %}
{{ description.content }}
{% endif %}