function content_taxonomy_autocomplete_tags_get_tids in Content Taxonomy 6.2
Same name and namespace in other branches
- 5 content_taxonomy_autocomplete.module \content_taxonomy_autocomplete_tags_get_tids()
- 6 content_taxonomy_autocomplete.module \content_taxonomy_autocomplete_tags_get_tids()
Get TIDs for freetagging tags Free tagging vocabularies do not send their tids in the form, so we'll detect them here and process them independently.
Parameters
$typed_input A string containing all comma separated tags. As the user typed it.:
1 call to content_taxonomy_autocomplete_tags_get_tids()
- content_taxonomy_autocomplete_validate in ./
content_taxonomy_autocomplete.module - Validation function for the content_taxonomy_autocomplete element
File
- ./
content_taxonomy_autocomplete.module, line 326 - Defines a widget type for content_taxonomy with autocomplete
Code
function content_taxonomy_autocomplete_tags_get_tids($typed_input, $vid, $parent = 0, $extra_parent = 0) {
$extra_parent_vid = 0;
if ($extra_parent) {
$extra_parent_term = taxonomy_get_term($extra_parent);
$extra_parent_vid = $extra_parent_term->vid;
}
// This regexp allows the following types of user input:
// this, "somecmpany, llc", "and ""this"" w,o.rks", foo bar
$typed_terms = content_taxonomy_autocomplete_split_tags($typed_input);
foreach ($typed_terms as $typed_term) {
// If a user has escaped a term (to demonstrate that it is a group,
// or includes a comma or quote character), we remove the escape
// formatting so to save the term into the DB as the user intends.
$typed_term = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $typed_term)));
if ($typed_term == "") {
continue;
}
// See if the term exists in the chosen vocabulary
// and return the tid, otherwise, add a new record.
$possibilities = taxonomy_get_term_by_name($typed_term);
$typed_term_tid = NULL;
// tid match if any.
foreach ($possibilities as $possibility) {
if ($possibility->vid == $vid || $extra_parent_vid != 0 && $possibility->vid == $extra_parent_vid) {
if ($parent) {
$parents = array();
$parents = taxonomy_get_parents($possibility->tid);
if (in_array($parent, array_keys($parents)) || in_array($extra_parent, array_keys($parents))) {
$result['existing_tids'][$possibility->tid] = $possibility->tid;
$typed_term_tid = $possibility->tid;
}
}
else {
$result['existing_tids'][$possibility->tid] = $possibility->tid;
$typed_term_tid = $possibility->tid;
}
}
}
if (!$typed_term_tid) {
$result['non_existing_terms'][] = array(
'name' => $typed_term,
'vid' => $vid,
);
}
}
return $result;
}