diff --git a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php index 6492127..fe509b4 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php @@ -210,7 +210,7 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select public function validateAutocompleteInput($input, &$element, &$form_state, $form) { $bundled_entities = $this->getReferencableEntities($input, '=', 6); $entities = array(); - foreach($bundled_entities as $bundle => $entities_list) { + foreach($bundled_entities as $entities_list) { $entities += $entities_list; } if (empty($entities)) { diff --git a/plugins/selection/abstract.inc b/plugins/selection/abstract.inc index 1d2ea0d..a267a97 100644 --- a/plugins/selection/abstract.inc +++ b/plugins/selection/abstract.inc @@ -21,8 +21,9 @@ interface EntityReference_SelectionHandler { * Return a list of referencable entities. * * @return - * An array of referencable entities, which keys are entity ids and - * values (safe HTML) labels to be displayed to the user. + * An 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 getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0); diff --git a/tests/entityreference.handlers.test b/tests/entityreference.handlers.test index b88e106..2256932 100644 --- a/tests/entityreference.handlers.test +++ b/tests/entityreference.handlers.test @@ -194,6 +194,21 @@ class EntityReferenceHandlersTestCase extends DrupalWebTestCase { ), ); $this->assertReferencable($field, $referencable_tests, 'Node handler (admin)'); + + // Verify autocomplete input validation. + $handler = entityreference_get_selection_handler($field); + $element = array( + '#parents' => array('element_name'), + ); + $form_state = array(); + $form = array(); + $value = $handler->validateAutocompleteInput($nodes['published1']->title, $element, $form_state, $form); + $this->assertEqual($value, $nodes['published1']->nid); + + $invalid_input = $this->randomName(); + $value = $handler->validateAutocompleteInput($invalid_input, $element, $form_state, $form); + $this->assertNull($value); + $this->assertEqual(form_get_error($element), t('There are no entities matching "%value"', array('%value' => $invalid_input))); } /**