diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php index 60920fad..f58edebd 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -90,7 +90,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen * The form state. */ public static function validateElement(array $element, FormStateInterface $form_state) { - if ($element['#required'] && $element['#value'] == '_none') { + if ($element['#required'] && $element['#value'] == '') { if (isset($element['#required_error'])) { $form_state->setError($element, $element['#required_error']); } @@ -113,7 +113,7 @@ public static function validateElement(array $element, FormStateInterface $form_ // Filter out the 'none' option. Use a strict comparison, because // 0 == 'any string'. - $index = array_search('_none', $values, TRUE); + $index = array_search('', $values, TRUE); if ($index !== FALSE) { unset($values[$index]); } diff --git a/core/modules/options/options.api.php b/core/modules/options/options.api.php index 15367cdd..0f67c290 100644 --- a/core/modules/options/options.api.php +++ b/core/modules/options/options.api.php @@ -33,7 +33,7 @@ function hook_options_list_alter(array &$options, array $context) { // Check if this is the field we want to change. if ($context['fieldDefinition']->getName() == 'field_option') { // Change the label of the empty option. - $options['_none'] = t('== Empty =='); + $options[''] = t('== Empty =='); } } diff --git a/core/modules/options/tests/src/Functional/OptionsSelectDynamicValuesTest.php b/core/modules/options/tests/src/Functional/OptionsSelectDynamicValuesTest.php index e27e6075..a18957ab 100644 --- a/core/modules/options/tests/src/Functional/OptionsSelectDynamicValuesTest.php +++ b/core/modules/options/tests/src/Functional/OptionsSelectDynamicValuesTest.php @@ -36,7 +36,7 @@ public function testSelectListDynamic(): void { $this->assertCount(count($this->test) + 1, $options); foreach ($options as $option) { $value = $option->getValue(); - if ($value != '_none') { + if ($value != '') { $this->assertContains($value, $this->test); } } diff --git a/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php b/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php index 99543ffe..757e1536 100644 --- a/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php +++ b/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php @@ -166,7 +166,7 @@ public function testRadioButtons(): void { $this->assertSession()->checkboxNotChecked('edit-card-1-2'); // Unselect option. - $edit = ['card_1' => '_none']; + $edit = ['card_1' => '']; $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_1', []); @@ -298,18 +298,18 @@ public function testSelectListSingle(): void { // Display form. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A required field without any value has a "none" option. - $option = $this->assertSession()->optionExists('edit-card-1', '_none'); + $option = $this->assertSession()->optionExists('edit-card-1', ''); $this->assertSame('- Select a value -', $option->getText()); // With no field data, nothing is selected. - $this->assertTrue($this->assertSession()->optionExists('card_1', '_none')->isSelected()); + $this->assertTrue($this->assertSession()->optionExists('card_1', '')->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_1', 0)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected()); $this->assertSession()->responseContains('Some dangerous & unescaped markup'); // Submit form: select invalid 'none' option. - $edit = ['card_1' => '_none']; + $edit = ['card_1' => '']; $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains("{$field->getName()} field is required."); @@ -321,7 +321,7 @@ public function testSelectListSingle(): void { // Display form: check that the right options are selected. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A required field with a value has no 'none' option. - $this->assertSession()->optionNotExists('edit-card-1', '_none'); + $this->assertEmpty($this->xpath('//select[@id=:id]//option[@value=""]', [':id' => 'edit-card-1']), 'A required select list with an actual value has no "none" choice.'); $this->assertTrue($this->assertSession()->optionExists('card_1', 0)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_1', 1)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected()); @@ -332,11 +332,11 @@ public function testSelectListSingle(): void { // Display form. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); - // A non-required field has a 'none' option. - $option = $this->assertSession()->optionExists('edit-card-1', '_none'); + // A non-required field has an empty '' option value. + $this->assertNotEmpty($this->xpath('//select[@id=:id]//option[@value="" and text()=:label]', [':id' => 'edit-card-1', ':label' => '- None -']), 'A non-required select list has a "None" choice.'); $this->assertSame('- None -', $option->getText()); // Submit form: Unselect the option. - $edit = ['card_1' => '_none']; + $edit = ['card_1' => '']; $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_1', []); @@ -368,7 +368,7 @@ public function testSelectListSingle(): void { $this->assertFalse($this->assertSession()->optionExists('card_1', 2)->isSelected()); // Submit form: Unselect the option. - $edit = ['card_1' => '_none']; + $edit = ['card_1' => '']; $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_1', []); @@ -439,7 +439,6 @@ public function testSelectListMultiple(): void { // Display form: with no field data, nothing is selected. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); - $this->assertTrue($this->assertSession()->optionExists('card_2', '_none')->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_2', 0)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_2', 1)->isSelected()); $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected()); @@ -481,13 +480,13 @@ public function testSelectListMultiple(): void { // Check that the 'none' option has no effect if actual options are selected // as well. - $edit = ['card_2[]' => ['_none' => '_none', 0 => 0]]; + $edit = ['card_2[]' => ['' => '', 0 => 0]]; $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_2', [0]); // Check that selecting the 'none' option empties the field. - $edit = ['card_2[]' => ['_none' => '_none']]; + $edit = ['card_2[]' => ['' => '']]; $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_2', []); @@ -531,7 +530,7 @@ public function testSelectListMultiple(): void { $this->assertFalse($this->assertSession()->optionExists('card_2', 2)->isSelected()); // Submit form: Unselect the option. - $edit = ['card_2[]' => ['_none' => '_none']]; + $edit = ['card_2[]' => ['' => '']]; $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->submitForm($edit, 'Save'); $this->assertFieldValues($entity_init, 'card_2', []); @@ -612,13 +611,9 @@ public function testEmptyValue(): void { ]); $entity->save(); - // Display form: check that _none options are present and has label. + // Display form: check that empty '' option is present and has label. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); - // Verify that a test radio button has a "None" choice. - $this->assertSession()->elementExists('xpath', '//div[@id="edit-card-1"]//input[@value="_none"]'); - // Verify that a test radio button has a "N/A" choice.. - $this->assertSession()->elementExists('xpath', '//div[@id="edit-card-1"]//label[@for="edit-card-1-none"]'); - $this->assertSession()->elementTextEquals('xpath', '//div[@id="edit-card-1"]//label[@for="edit-card-1-none"]', "N/A"); + $this->assertNotEmpty($this->xpath('//div[@id=:id]//input[@value=:value]', [':id' => 'edit-card-1', ':value' => '']), 'A test radio button has a "None" choice.'); // Change it to the select widget. $display_repository->getFormDisplay('entity_test', 'entity_test') @@ -627,10 +622,10 @@ public function testEmptyValue(): void { ]) ->save(); - // Display form: check that _none options are present and has label. + // Display form: check that '' options are present and has label. $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A required field without any value has a "none" option. - $option = $this->assertSession()->optionExists('edit-card-1', '_none'); + $option = $this->assertSession()->optionExists('edit-card-1', ''); $this->assertSame('- None -', $option->getText()); } diff --git a/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php b/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php index 56e91d8a..51921e96 100644 --- a/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php @@ -94,12 +94,12 @@ protected function createAndActivateWorkspaceThroughUi(?string $label = NULL, ?s * @param string|null $id * The ID of the workspace to create. * @param string $parent - * (optional) The ID of the parent workspace. Defaults to '_none'. + * (optional) The ID of the parent workspace. Defaults to ''. * * @return \Drupal\workspaces\WorkspaceInterface * The workspace that was just created. */ - protected function createWorkspaceThroughUi(?string $label = NULL, ?string $id = NULL, string $parent = '_none') { + protected function createWorkspaceThroughUi(?string $label = NULL, ?string $id = NULL, string $parent = '') { $id ??= $this->randomMachineName(); $label ??= $this->randomString();