diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 41c9e85e4d2f0152da723e55d330d16de8aaf1aa..a7c8166a7506035a1a1c20a5f0176c1c690614c3 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1659,7 +1659,15 @@ function template_preprocess_field_multiple_value_form(&$variables) { ), ); - $variables['description'] = $element['#description']; + if (!empty($element['#description'])) { + $description_id = $element['#attributes']['aria-describedby']; + $description_attributes['id'] = $description_id; + $variables['description']['attributes'] = new Attribute($description_attributes); + $variables['description']['content'] = $element['#description']; + + // Add the description's id to the table aria attributes. + $variables['table']['#attributes']['aria-describedby'] = $element['#attributes']['aria-describedby']; + } } else { $variables['elements'] = array(); diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 0ae049bbb8fa3f9a72a5539336cf5b0ccb2cc99f..9e70b3821cec0b40d76a1981fd3dd17e98584c9a 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -254,6 +254,10 @@ function testFieldFormUnlimited() { $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget 1 is displayed'); $this->assertNoField("{$field_name}[1][value]", 'No extraneous widget is displayed'); + // Check if aria-describedby attribute is placed on multiple value widgets. + $elements = $this->xpath('//table[@id="field-unlimited-values" and @aria-describedby="edit-field-unlimited--description"]'); + $this->assertTrue(isset($elements[0]), t('aria-describedby attribute is properly placed on multiple value widgets.')); + // Press 'add more' button -> 2 widgets. $this->drupalPostForm(NULL, array(), t('Add another item')); $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget 1 is displayed'); diff --git a/core/modules/system/templates/field-multiple-value-form.html.twig b/core/modules/system/templates/field-multiple-value-form.html.twig index 348621ce98ca965a656b0d68ef8d057efb598fa7..1108d6eb76b270b175841078f4860abaea73d772 100644 --- a/core/modules/system/templates/field-multiple-value-form.html.twig +++ b/core/modules/system/templates/field-multiple-value-form.html.twig @@ -11,7 +11,9 @@ * * Available variables when there are multiple fields. * - table: Table of field items. - * - description: Description text for the form element. + * - description: The description element containing the following properties: + * - content: The description content of the form element. + * - attributes: HTML attributes to apply to the description container. * - button: "Add another item" button. * * @see template_preprocess_field_multiple_value_form() @@ -22,8 +24,8 @@ {% if multiple %}
{{ table }} - {% if description %} -
{{ description }}
+ {% if description.content %} + {{ description.content }}
{% endif %} {% if button %}
{{ button }}
diff --git a/core/themes/classy/templates/form/field-multiple-value-form.html.twig b/core/themes/classy/templates/form/field-multiple-value-form.html.twig index bcc7b89bb58187325da4129e7015b5ff5b44b586..6ac2ddf41a3ea4aaf470f600b2999911c93a54ec 100644 --- a/core/themes/classy/templates/form/field-multiple-value-form.html.twig +++ b/core/themes/classy/templates/form/field-multiple-value-form.html.twig @@ -11,7 +11,9 @@ * * Available variables when there are multiple fields. * - table: Table of field items. - * - description: Description text for the form element. + * - description: The description element containing the following properties: + * - content: The description content of the form element. + * - attributes: HTML attributes to apply to the description container. * - button: "Add another item" button. * * @see template_preprocess_field_multiple_value_form() @@ -20,8 +22,8 @@ {% if multiple %}
{{ table }} - {% if description %} -
{{ description }}
+ {% if description.content %} + {{ description.content }}
{% endif %} {% if button %}
{{ button }}