Loading core/lib/Drupal/Core/Render/Element/Checkboxes.php +8 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,13 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta $element['#default_value'] = []; } $weight = 0; $child_attributes = $element['#attributes']; // Prevent child elements from inheriting an aria-describedby attribute. // The individual children won't have descriptions and the attribute will // be invalid. if (isset($child_attributes['aria-describedby'])) { unset($child_attributes['aria-describedby']); } foreach ($element['#options'] as $key => $choice) { // Integer 0 is not a valid #return_value, so use '0' instead. // @see \Drupal\Core\Render\Element\Checkbox::valueCallback(). Loading @@ -91,7 +98,7 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta '#title' => $choice, '#return_value' => $key, '#default_value' => $default_value, '#attributes' => $element['#attributes'], '#attributes' => $child_attributes, '#ajax' => $element['#ajax'] ?? NULL, // Errors should only be shown on the parent checkboxes element. '#error_no_message' => TRUE, Loading core/lib/Drupal/Core/Render/Element/Radios.php +8 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,13 @@ public function getInfo() { public static function processRadios(&$element, FormStateInterface $form_state, &$complete_form) { if (count($element['#options']) > 0) { $weight = 0; $child_attributes = $element['#attributes']; // Prevent child elements from inheriting an aria-describedby attribute. // The individual children won't have descriptions and the attribute will // be invalid. if (isset($child_attributes['aria-describedby'])) { unset($child_attributes['aria-describedby']); } foreach ($element['#options'] as $key => $choice) { // Maintain order of options as defined in #options, in case the element // defines custom option sub-elements, but does not define all option Loading @@ -79,7 +86,7 @@ public static function processRadios(&$element, FormStateInterface $form_state, // Use default or FALSE. A value of FALSE means that the radio button // is not 'checked'. '#default_value' => $element['#default_value'] ?? FALSE, '#attributes' => $element['#attributes'], '#attributes' => $child_attributes, '#parents' => $element['#parents'], '#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)), '#ajax' => $element['#ajax'] ?? NULL, Loading core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $customiz $form['checkboxes'] = [ '#type' => 'checkboxes', '#title' => 'Checkboxes', '#description' => 'Checkboxes description', '#options' => [ 0 => 'Zero', 'foo' => 'Foo', Loading @@ -55,6 +56,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $customiz $form['radios'] = [ '#type' => 'radios', '#title' => 'Radios', '#description' => 'Radios description', '#options' => [ 0 => 'Zero', 'foo' => 'Foo', Loading core/modules/system/tests/src/Functional/Form/ElementTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ public function testFormElements(): void { $this->testOptions(); $this->testRadiosChecked(); $this->testWrapperIds(); $this->testChildAttributes(); $this->testButtonClasses(); $this->testSubmitButtonAttribute(); $this->testGroupElements(); Loading Loading @@ -138,6 +139,17 @@ protected function testWrapperIds(): void { } } /** * Tests checkboxes and radios child element attributes. */ protected function testChildAttributes(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that the child elements don't have aria-describedby attributes. $this->assertSession()->elementsCount('xpath', "//input[@type='checkbox' and @aria-describedby]", 0); $this->assertSession()->elementsCount('xpath', "//input[@type='radio' and @aria-describedby]", 0); } /** * Tests button classes. */ Loading Loading
core/lib/Drupal/Core/Render/Element/Checkboxes.php +8 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,13 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta $element['#default_value'] = []; } $weight = 0; $child_attributes = $element['#attributes']; // Prevent child elements from inheriting an aria-describedby attribute. // The individual children won't have descriptions and the attribute will // be invalid. if (isset($child_attributes['aria-describedby'])) { unset($child_attributes['aria-describedby']); } foreach ($element['#options'] as $key => $choice) { // Integer 0 is not a valid #return_value, so use '0' instead. // @see \Drupal\Core\Render\Element\Checkbox::valueCallback(). Loading @@ -91,7 +98,7 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta '#title' => $choice, '#return_value' => $key, '#default_value' => $default_value, '#attributes' => $element['#attributes'], '#attributes' => $child_attributes, '#ajax' => $element['#ajax'] ?? NULL, // Errors should only be shown on the parent checkboxes element. '#error_no_message' => TRUE, Loading
core/lib/Drupal/Core/Render/Element/Radios.php +8 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,13 @@ public function getInfo() { public static function processRadios(&$element, FormStateInterface $form_state, &$complete_form) { if (count($element['#options']) > 0) { $weight = 0; $child_attributes = $element['#attributes']; // Prevent child elements from inheriting an aria-describedby attribute. // The individual children won't have descriptions and the attribute will // be invalid. if (isset($child_attributes['aria-describedby'])) { unset($child_attributes['aria-describedby']); } foreach ($element['#options'] as $key => $choice) { // Maintain order of options as defined in #options, in case the element // defines custom option sub-elements, but does not define all option Loading @@ -79,7 +86,7 @@ public static function processRadios(&$element, FormStateInterface $form_state, // Use default or FALSE. A value of FALSE means that the radio button // is not 'checked'. '#default_value' => $element['#default_value'] ?? FALSE, '#attributes' => $element['#attributes'], '#attributes' => $child_attributes, '#parents' => $element['#parents'], '#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)), '#ajax' => $element['#ajax'] ?? NULL, Loading
core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $customiz $form['checkboxes'] = [ '#type' => 'checkboxes', '#title' => 'Checkboxes', '#description' => 'Checkboxes description', '#options' => [ 0 => 'Zero', 'foo' => 'Foo', Loading @@ -55,6 +56,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $customiz $form['radios'] = [ '#type' => 'radios', '#title' => 'Radios', '#description' => 'Radios description', '#options' => [ 0 => 'Zero', 'foo' => 'Foo', Loading
core/modules/system/tests/src/Functional/Form/ElementTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ public function testFormElements(): void { $this->testOptions(); $this->testRadiosChecked(); $this->testWrapperIds(); $this->testChildAttributes(); $this->testButtonClasses(); $this->testSubmitButtonAttribute(); $this->testGroupElements(); Loading Loading @@ -138,6 +139,17 @@ protected function testWrapperIds(): void { } } /** * Tests checkboxes and radios child element attributes. */ protected function testChildAttributes(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that the child elements don't have aria-describedby attributes. $this->assertSession()->elementsCount('xpath', "//input[@type='checkbox' and @aria-describedby]", 0); $this->assertSession()->elementsCount('xpath', "//input[@type='radio' and @aria-describedby]", 0); } /** * Tests button classes. */ Loading