';
+ $output .= $prefix . '
\n";
return $output;
}
@@ -985,7 +996,7 @@ function theme_fieldset($variables) {
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children, #collapsed, #description, #id,
- * #title, #value.
+ * #title, #title_display, #value.
*
* @ingroup themeable
*/
@@ -1012,7 +1023,7 @@ function theme_details($variables) {
}
$output .= $element['#children'];
if (isset($element['#value'])) {
- $output .= $element['#value'];
+ $output .= $element['#value'];
}
$output .= '
';
$output .= "\n";
@@ -1251,11 +1262,15 @@ function theme_checkboxes($variables) {
}
/**
- * Adds form element theming to an element if its title or description is set.
+ * Adds theming to composite form elements such as checkboxes and radios.
*
- * This is used as a pre render function for checkboxes and radios.
+ * If either the title or description is set for the composite element as a * whole, then this adds either a 'fieldset' or 'form_element' theme wrapper to
+ * render them. A fieldset is generally preferred to assist screen readers
+ * (http://webaim.org/techniques/forms/screen_reader#group), but is not used
+ * when #title_display is set to an option impossible to render as a fieldset
+ * legend.
*/
-function form_pre_render_conditional_form_element($element) {
+function form_pre_render_composite_form_element($element) {
// Set the element's title attribute to show #title as a tooltip, if needed.
if (isset($element['#title']) && $element['#title_display'] == 'attribute') {
$element['#attributes']['title'] = $element['#title'];
@@ -1266,7 +1281,16 @@ function form_pre_render_conditional_form_element($element) {
}
if (isset($element['#title']) || isset($element['#description'])) {
- $element['#theme_wrappers'][] = 'form_element';
+ // To assist screen readers, use a fieldset wrapper when possible, but
+ // fieldset legends are only compatible with the 'before' and 'invisible'
+ // options for #title_display.
+ if (!isset($element['#title_display']) || in_array($element['#title_display'], array('before', 'invisible'))) {
+ $wrapper = 'fieldset';
+ }
+ else {
+ $wrapper = 'form_element';
+ }
+ $element['#theme_wrappers'][] = $wrapper;
}
return $element;
}
@@ -2710,7 +2734,7 @@ function form_process_file($element) {
* property hides the label for everyone except screen readers.
* - attribute: Set the title attribute on the element to create a tooltip
* but output no label element. This is supported only for checkboxes
- * and radios in form_pre_render_conditional_form_element(). It is used
+ * and radios in form_pre_render_composite_form_element(). It is used
* where a visual label is not needed, such as a table of checkboxes where
* the row and column provide the context. The tooltip will include the
* title and required marker.
diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php
index 6c51a04..02bc1d9 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Form/ElementsLabelsTest.php
@@ -78,10 +78,10 @@ function testFormLabels() {
$this->assertFalse(isset($elements[0]), 'No label tag when title set not to display.');
// Check #field_prefix and #field_suffix placement.
- $elements = $this->xpath('//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]');
+ $elements = $this->xpath('//span[@class="field-prefix"]/following-sibling::fieldset[@id="edit-form-radios-test"]');
$this->assertTrue(isset($elements[0]), 'Properly placed the #field_prefix element after the label and before the field.');
- $elements = $this->xpath('//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]');
+ $elements = $this->xpath('//span[@class="field-suffix"]/preceding-sibling::fieldset[@id="edit-form-radios-test"]');
$this->assertTrue(isset($elements[0]), 'Properly places the #field_suffix element immediately after the form field.');
// Check #prefix and #suffix placement.
diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
index 6563339..8ebf450 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php
@@ -94,7 +94,7 @@ function testRequiredFields() {
$elements['file']['empty_values'] = $empty_strings;
// Regular expression to find the expected marker on required elements.
- $required_marker_preg = '@