function taxonomy_unique_is_term_unique in Taxonomy unique 7
Same name and namespace in other branches
- 8 taxonomy_unique.module \taxonomy_unique_is_term_unique()
Checks if term name already exists in vocabulary.
Parameters
string $term_name: Name to check
string $vocabulary_machine_name: Machine name of the vocabulary the term belongs to
int $tid: The term ID when updating an existing term
Return value
bool TRUE when term name is unique, FALSE if not
2 calls to taxonomy_unique_is_term_unique()
- taxonomy_unique_form_taxonomy_manager_form_add_validate in ./
taxonomy_unique.module - Validation handler for taxonomy_manager_form() 'add' button.
- taxonomy_unique_term_name_validate in ./
taxonomy_unique.module - Implements _form_validate() for taxonomy_form_term().
File
- ./
taxonomy_unique.module, line 159 - Module file for the Taxonomy unique module.
Code
function taxonomy_unique_is_term_unique($term_name, $vocabulary_machine_name, $tid = NULL) {
$terms = taxonomy_get_term_by_name($term_name, $vocabulary_machine_name);
$term = current($terms);
// If no terms are found, or only one term is found which has
// the same tid as the one we're trying to save, the name must be unique.
if (empty($terms) || count($terms) == 1 && $term->tid == $tid) {
return TRUE;
}
return FALSE;
}