commit eda7f70f9651fb0bc381160aa490067d67046aa1 Author: Kozma Adrian Date: Sat Jan 25 17:18:32 2014 +0200 Reroll for #1379070. diff --git a/core/includes/form.inc b/core/includes/form.inc index e4f7982..82e568b 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -858,6 +858,7 @@ function form_select_options($element, $choices = NULL) { // isset() fails in this situation. $value_valid = isset($element['#value']) || array_key_exists('#value', $element); $value_is_array = $value_valid && is_array($element['#value']); + $empty_value = (empty($element['#value']) && isset($element['#properties']['empty_option'])); $options = ''; foreach ($choices as $key => $choice) { if (is_array($choice)) { @@ -870,7 +871,8 @@ function form_select_options($element, $choices = NULL) { } else { $key = (string) $key; - if ($value_valid && (!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) { + $empty_choice = $empty_value && $key == '_none'; + if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $empty_choice)) { $selected = ' selected="selected"'; } else { diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 02304b6..c0038c2 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -378,6 +378,7 @@ function testSelectListMultiple() { // Display form: with no field data, nothing is selected. $this->drupalGet('entity_test/manage/' . $entity->id()); + $this->assertOptionSelected("edit-card-2", '_none'); $this->assertNoOptionSelected('edit-card-2', 0); $this->assertNoOptionSelected('edit-card-2', 1); $this->assertNoOptionSelected('edit-card-2', 2);