private function TaxonomyUniqueValidator::isUnique in Taxonomy unique 8.2
Checks if given term is unique inside its vocabulary.
Parameters
TermInterface $term: The term to check.
Return value
bool Whether the term is unique or not
1 call to TaxonomyUniqueValidator::isUnique()
- TaxonomyUniqueValidator::validate in src/
Plugin/ Validation/ Constraint/ TaxonomyUniqueValidator.php - Checks if the passed value is valid.
File
- src/
Plugin/ Validation/ Constraint/ TaxonomyUniqueValidator.php, line 38
Class
- TaxonomyUniqueValidator
- Taxonomy unique constraint validator.
Namespace
Drupal\taxonomy_unique\Plugin\Validation\ConstraintCode
private function isUnique(TermInterface $term) {
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties([
'name' => $term
->getName(),
'vid' => $term
->bundle(),
]);
if (empty($terms)) {
return TRUE;
}
if (count($terms) == 1) {
$found_term = current($terms);
if ($found_term
->id() == $term
->id()) {
return TRUE;
}
}
return FALSE;
}