function taxonomy_dupecheck_is_dupe_term in Taxonomy dupecheck 7
Same name and namespace in other branches
- 6 taxonomy_dupecheck.module \taxonomy_dupecheck_is_dupe_term()
Checks whether a term is a duplicate, based on the module preferences.
Parameters
$term: Name of the new term to check
int $vid: ID of the vocabulary the new term belongs to
int $tid: Term ID of the new term (used when updating an existing term name)
Return value
bool TRUE if the term is a duplicate, FALSE if not
1 call to taxonomy_dupecheck_is_dupe_term()
- taxonomy_dupecheck_term_validate in ./
taxonomy_dupecheck.module - Implements _form_validate() for taxonomy_form_term().
File
- ./
taxonomy_dupecheck.module, line 159 - Module file for the Taxonomy dupecheck module.
Code
function taxonomy_dupecheck_is_dupe_term($term, $vid, $tid = 0) {
// Clean up the term to check
$term = trim($term);
// Get matching terms in the given vocabulary (case insensitive)
$query = new EntityFieldQuery();
$query = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('name', $term)
->propertyCondition('vid', $vid);
if ($tid) {
// Ignore an existing term of the same name; this is needed on updates to an existing term.
$query = $query
->entityCondition('entity_id', $tid, '<>');
}
$result = $query
->execute();
// No results, term is unique
if (is_array($result) && !$result) {
return FALSE;
}
// We found a result
if (isset($result['taxonomy_term'])) {
// Do a case sensitive comparison if requested, but if not,
// just return that we found a match
if (variable_get('taxonomy_dupecheck_case_sensitive')) {
$is_dupe = FALSE;
// For each found result...
foreach ($result['taxonomy_term'] as $found_term) {
// Load the term data and see if it's a dupe
$term_data = taxonomy_term_load($found_term->tid);
if (!strcmp($term_data->name, $term)) {
$is_dupe = TRUE;
break;
}
}
return $is_dupe;
}
else {
// Not case sensitive
return TRUE;
}
}
return FALSE;
}