diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index a9c0dd3..652af59 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -418,26 +418,15 @@ public function getAllBundleInfo() { */ public function getEntityTypeLabels($group = FALSE) { $options = array(); - $groups = array(); - $group_options = array(); foreach ($this->getDefinitions() as $entity_type => $definition) { - if ($group) { - $group_label = $definition->getGroupLabel() ?: $this->translationManager->translate('Content', array(), array('context' => 'Entity type group')); - $groups[$group_label] = $group_label; - $group_options[$group_label][$entity_type] = $definition->getLabel(); + if ($group && ($group_label = $definition->getGroupLabel())) { + $options[$group_label][$entity_type] = $definition->getLabel(); } else { $options[$entity_type] = $definition->getLabel(); } } - - if ($group) { - natcasesort($groups); - foreach ($groups as $group_label) { - natcasesort($group_options[$group_label]); - $options[$group_label] = $group_options[$group_label]; - } - } + array_multisort($options); return $options; } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php index 37cf7bb..54eea8f 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php @@ -42,7 +42,7 @@ protected function assertFieldSelectOptions($name, $expected_options) { if ($fields) { $field = $fields[0]; $options = $this->getAllOptionsList($field); - return $this->assertIdentical($options, $expected_options); + return $this->assertIdentical(sort($options), sort($expected_options)); } else { return $this->fail(t('Unable to find field @name', array('@name' => $name))); @@ -58,7 +58,11 @@ protected function getAllOptionsList($element) { foreach ($element->option as $option) { $options[] = (string) $option['value']; } - // TODO: support optgroup. + + if (isset($element->optgroup)) { + $options += $this->getAllOptionsList($element->optgroup); + } + return $options; } @@ -76,9 +80,7 @@ public function testFieldAdminHandler() { $this->assertFieldByName('field[settings][target_type]', 'node'); // Check that all entity types can be referenced. - foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) { - $this->assertFieldByXPath("//select[@name='field[settings][target_type]']/option[@value='" . $entity_type_id . "']"); - } + $this->assertFieldSelectOptions('field[settings][target_type]', array_keys(\Drupal::entityManager()->getDefinitions())); // Second step: 'Instance settings' form. $this->drupalPostForm(NULL, array(), t('Save field settings')); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index a442dd0..ebc4a97 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -3041,7 +3041,7 @@ protected function assertFieldByXPath($xpath, $value = NULL, $message = '', $gro // Input element with correct value. $found = TRUE; } - elseif (isset($field->option)) { + elseif (isset($field->option) || isset($field->optgroup)) { // Select element found. if ($this->getSelectedItem($field) == $value) { $found = TRUE;