You are here

public function TaxonomyUniqueValidator::validate in Taxonomy unique 8.2

File

src/Plugin/Validation/Constraint/TaxonomyUniqueValidator.php, line 17

Class

TaxonomyUniqueValidator
Taxonomy unique constraint validator.

Namespace

Drupal\taxonomy_unique\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {

  /** @var TermInterface $term */
  $term = $value
    ->getEntity();
  if (\Drupal::config('taxonomy_unique.settings')
    ->get($term
    ->bundle()) && !$this
    ->isUnique($term)) {
    $message = \Drupal::config('taxonomy_unique.settings')
      ->get($term
      ->bundle() . '_message');
    if ($message != '') {
      $constraint
        ->setErrorMessage($message);
    }
    $this->context
      ->addViolation($constraint->notUnique, [
      '%term' => $term
        ->getName(),
      '%vocabulary' => $term
        ->bundle(),
    ]);
  }
}