function ConstraintViolationBuilder::addViolation

Same name in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Validation/ConstraintViolationBuilder.php \Drupal\Core\TypedData\Validation\ConstraintViolationBuilder::addViolation()
  2. 10 core/lib/Drupal/Core/Validation/ConstraintViolationBuilder.php \Drupal\Core\Validation\ConstraintViolationBuilder::addViolation()
  3. 11.x core/lib/Drupal/Core/Validation/ConstraintViolationBuilder.php \Drupal\Core\Validation\ConstraintViolationBuilder::addViolation()

File

core/lib/Drupal/Core/TypedData/Validation/ConstraintViolationBuilder.php, line 216

Class

ConstraintViolationBuilder
Defines a constraint violation builder for the Typed Data validator.

Namespace

Drupal\Core\TypedData\Validation

Code

public function addViolation() {
    if (null === $this->plural) {
        $translatedMessage = $this->translator
            ->trans($this->message, $this->parameters, $this->translationDomain);
    }
    else {
        try {
            $translatedMessage = $this->translator
                ->transChoice($this->message, $this->plural, $this->parameters, $this->translationDomain);
        } catch (\InvalidArgumentException $e) {
            $translatedMessage = $this->translator
                ->trans($this->message, $this->parameters, $this->translationDomain);
        }
    }
    $this->violations
        ->add(new ConstraintViolation($translatedMessage, $this->message, $this->parameters, $this->root, $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.