function _term_reference_autocomplete_validate in Taxonomy Term Reference Filter by Views 7.2
1 string reference to '_term_reference_autocomplete_validate'
- term_reference_filter_by_views_field_widget_form_alter in ./
term_reference_filter_by_views.module - Implements hook_widget_field_form(). Alters the Taxonomy Term Reference Widgets.
File
- ./
term_reference_filter_by_views.module, line 82
Code
function _term_reference_autocomplete_validate($element, &$form_state, $form) {
// If a value was entered into the autocomplete...
$value = '';
if (!empty($element['#value'])) {
if (isset($element['#multiple']) && $element['value_field']['#type'] == 'textfield') {
$terms_data = drupal_explode_tags($element['#value']);
}
else {
$terms_data = array(
$element['#value'],
);
}
foreach ($terms_data as $term_data) {
// Take "label (term id)', match the id from parenthesis.
if (preg_match("/.+\\(\\s*id\\s*:(\\d+)\\)/", $term_data, $matches)) {
if ($element['#instance']['widget']['type'] == 'references_dialog_term_reference') {
$value = $matches[1];
}
else {
$value[] = (array) taxonomy_term_load($matches[1]);
}
}
else {
$value[] = NULL;
}
}
}
// Update the value of this element so the field can validate the product IDs.
form_set_value($element, $value, $form_state);
}