1 entityreference.module | _entityreference_autocomplete_tags_validate($element, &$form_state, $form) |
Implements hook_validate().
File
- core/
modules/ entityreference/ entityreference.module, line 928 - Entityreference primary module file.
Code
function _entityreference_autocomplete_tags_validate($element, &$form_state, $form) {
$value = array();
// If a value was entered into the autocomplete...
if (!empty($element['#value'])) {
$entities = backdrop_explode_tags($element['#value']);
$value = array();
foreach ($entities as $entity) {
// Take "label (entity id)', match the id from parenthesis.
if (preg_match("/.+\((\d+)\)/", $entity, $matches)) {
$value[] = array(
'target_id' => $matches[1],
);
}
else {
// Try to get a match from the input string when the user didn't use the
// autocomplete but filled in a value manually.
$field = field_info_field($element['#field_name']);
$handler = entityreference_get_selection_handler($field);
$value[] = array(
'target_id' => $handler->validateAutocompleteInput($entity, $element, $form_state, $form),
);
}
}
}
// Update the value of this element so the field can validate the product IDs.
form_set_value($element, $value, $form_state);
}