function menu_position_taxonomy_autocomplete_validate in Menu Position 7
Same name and namespace in other branches
- 7.2 plugins/menu_position.taxonomy.inc \menu_position_taxonomy_autocomplete_validate()
Form element validate handler for taxonomy term autocomplete element.
1 string reference to 'menu_position_taxonomy_autocomplete_validate'
- menu_position_menu_position_rule_taxonomy_form in plugins/
menu_position.taxonomy.inc - Adds form elements for the "taxonomy" plugin to the rule configuration form.
File
- plugins/
menu_position.taxonomy.inc, line 280 - Provides the "Taxonomy" rule plugin for the Menu Position module.
Code
function menu_position_taxonomy_autocomplete_validate($element, &$form_state) {
// Autocomplete widgets do not send their tids in the form, so we must detect
// them here and process them independently.
$value = array();
if ($tags = $element['#value']) {
// Translate term names into actual terms.
$typed_terms = drupal_explode_tags($tags);
foreach ($typed_terms as $typed_term) {
// See if the term exists in the chosen vocabulary and return the tid;
// otherwise, create a new 'autocreate' term for insert/update.
if ($possibilities = taxonomy_term_load_multiple(array(), array(
'name' => trim($typed_term),
'vid' => array(
$form_state['values']['vid'],
),
))) {
$term = array_pop($possibilities);
$value[] = (array) $term;
}
else {
form_set_error('term', t('%term is not a valid taxonomy term.', array(
'%term' => $typed_term,
)));
}
}
}
if (!empty($value)) {
form_set_value($element, $value, $form_state);
}
}