diff --git a/plugins/selection/EntityReference_SelectionHandler_Views.class.php b/plugins/selection/EntityReference_SelectionHandler_Views.class.php index 1b036a7..881e0ae 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Views.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Views.class.php @@ -147,7 +147,38 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio * Implements EntityReferenceHandler::validateAutocompleteInput(). */ public function validateAutocompleteInput($input, &$element, &$form_state, $form) { - return NULL; + $bundled_entities = $this->getReferencableEntities($input, '=', 6); + $entities = array(); + foreach ($bundled_entities as $entities_list) { + $entities += $entities_list; + } + if (empty($entities)) { + // Error if there are no entities available for a required field. + form_error($element, t('No items found for %label', array('%label' => $element['#title']))); + } + elseif (count($entities) > 5) { + // Error if there are more than 5 matching entities. + form_error($element, t('Too many items found for %label. Specify the one you want by appending the id in parentheses, like "@value (@id)"', array( + '%label' => $element['#title'], + '@value' => $input, + '@id' => key($entities), + ))); + } + elseif (count($entities) > 1) { + // More helpful error if there are only a few matching entities. + $multiples = array(); + foreach ($entities as $id => $name) { + $multiples[] = filter_xss($name, array()) . ' (' . (int) $id . ')'; + } + form_error($element, t('Multiple items found for %label: !multiple', array( + '%label' => $element['#title'], + '!multiple' => theme('item_list', array('items' => $multiples)), + ))); + } + else { + // Take the one and only matching entity. + return (int) key($entities); + } } /**