diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php index c23de90..480d30b 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -65,6 +65,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['#element_validate'][] = array(get_class($this), 'validateElement'); $element['#key_column'] = $this->column; + if ($empty_option = $this->getEmptyOption()) { + $element['#properties']['empty_option'] = 'none'; + } // The rest of the $element is built by child method implementations. return $element; diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index c0038c2..2527211 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -376,7 +376,8 @@ function testSelectListMultiple() { $entity->save(); $entity_init = clone $entity; - // Display form: with no field data, nothing is selected. + // Display form: with no field data, nothing is selected, except for the + // empty option. $this->drupalGet('entity_test/manage/' . $entity->id()); $this->assertOptionSelected("edit-card-2", '_none'); $this->assertNoOptionSelected('edit-card-2', 0);