diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 243a9af..1663045 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -138,7 +138,6 @@ public static function setAttributes(&$element, $class = []) { // \Drupal::formBuilder()->doBuildForm(). if (!empty($element['#required'])) { $element['#attributes']['class'][] = 'required'; - $element['#attributes']['required'] = 'required'; $element['#attributes']['aria-required'] = 'true'; } if (isset($element['#parents']) && isset($element['#errors']) && !empty($element['#validated'])) { diff --git a/core/modules/filter/src/Tests/FilterFormTest.php b/core/modules/filter/src/Tests/FilterFormTest.php index 9d0641e..dde1698 100644 --- a/core/modules/filter/src/Tests/FilterFormTest.php +++ b/core/modules/filter/src/Tests/FilterFormTest.php @@ -250,7 +250,7 @@ protected function assertOptions($id, array $expected_options, $selected) { * TRUE if the assertion passed; FALSE otherwise. */ protected function assertRequiredSelectAndOptions($id, array $options) { - $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [ + $select = $this->xpath('//select[@id=:id and contains(@class, "required")]', [ ':id' => $id, ]); $select = reset($select); diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php index 4b8d042..a61c818 100644 --- a/core/modules/system/src/Tests/Form/FormTest.php +++ b/core/modules/system/src/Tests/Form/FormTest.php @@ -723,27 +723,4 @@ public function testInputForgery() { $this->assertText('An illegal choice has been detected.', 'Input forgery was detected.'); } - /** - * Tests required attribute. - */ - public function testRequiredAttribute() { - $this->drupalGet('form-test/required-attribute'); - $expected = 'required'; - // Test to make sure the elements have the proper required attribute. - foreach (['textfield', 'password'] as $type) { - $element = $this->xpath('//input[@id=:id and @required=:expected]', [ - ':id' => 'edit-' . $type, - ':expected' => $expected, - ]); - $this->assertTrue(!empty($element), format_string('The @type has the proper required attribute.', ['@type' => $type])); - } - - // Test to make sure textarea has the proper required attribute. - $element = $this->xpath('//textarea[@id=:id and @required=:expected]', [ - ':id' => 'edit-textarea', - ':expected' => $expected, - ]); - $this->assertTrue(!empty($element), 'The textarea has the proper required attribute.'); - } - } diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml index 2250a0b..4233b1b 100644 --- a/core/modules/system/tests/modules/form_test/form_test.routing.yml +++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml @@ -394,9 +394,9 @@ form_test.checkboxes_zero: _access: 'TRUE' form_test.required: - path: '/form-test/required-attribute' + path: '/form-test/required-fields' defaults: - _form: '\Drupal\form_test\Form\FormTestRequiredAttributeForm' + _form: '\Drupal\form_test\Form\FormTestRequiredFieldsForm' _title: 'Required' requirements: _access: 'TRUE' diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php similarity index 82% rename from core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php rename to core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php index b0aa1b0..bdbc343 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php @@ -6,15 +6,15 @@ use Drupal\Core\Form\FormStateInterface; /** - * Builds a form to test the required attribute. + * Builds a form to test required fields. */ -class FormTestRequiredAttributeForm extends FormBase { +class FormTestRequiredFieldsForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { - return 'form_test_required_attribute'; + return 'form_test_required_fields'; } /**