diff --git a/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionInterface.php b/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionInterface.php index 458c1cb18b20e34274adc52c6a91a9575ecf95db..27e1f214fc9f711bedf9ff098e7ba5b2fe1ec310 100644 --- a/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionInterface.php +++ b/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionInterface.php @@ -24,8 +24,9 @@ interface SelectionInterface { * Returns a list of referenceable entities. * * @return array - * An array of referenceable entities. Keys are entity IDs and - * values are (safe HTML) labels to be displayed to the user. + * A nested array of entities, the first level is keyed by the + * entity bundle, which contains an array of entity labels (safe HTML), + * keyed by the entity ID. */ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0); diff --git a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php index 9d67882e5a5f26d6d19f11fbb9e9329421a0be52..650486c692710636e925672d5ec61d9f59f61e3b 100644 --- a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php @@ -220,7 +220,11 @@ public function validateReferenceableEntities(array $ids) { * {@inheritdoc} */ public function validateAutocompleteInput($input, &$element, &$form_state, $form, $strict = TRUE) { - $entities = $this->getReferenceableEntities($input, '=', 6); + $bundled_entities = $this->getReferenceableEntities($input, '=', 6); + $entities = array(); + foreach ($bundled_entities as $entities_list) { + $entities += $entities_list; + } $params = array( '%value' => $input, '@value' => $input, diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php index 3a892b2652f70d2327cad1f013a2f8b87e0b18ed..cd6a7b5cd1956fe137bbb5a996e3328a258f4775 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php @@ -79,7 +79,8 @@ public function testSupportedEntityTypesAndWidgets() { 'name' => $entity_name, 'user_id' => mt_rand(0, 128), $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', - $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')', + // Test an input of the entity label without a ' (entity_id)' suffix. + $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(), ); $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); @@ -97,7 +98,8 @@ public function testSupportedEntityTypesAndWidgets() { $entity_name = $this->randomName(); $target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'; - $target_id .= ', ' . $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')'; + // Test an input of the entity label without a ' (entity_id)' suffix. + $target_id .= ', ' . $referenced_entities[1]->label(); $edit = array( 'name' => $entity_name, 'user_id' => mt_rand(0, 128),