You are here

public function ExecutionContext::addViolation in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/ExecutionContext.php \Symfony\Component\Validator\ExecutionContext::addViolation()
  2. 8 vendor/symfony/validator/Context/ExecutionContext.php \Symfony\Component\Validator\Context\ExecutionContext::addViolation()
  3. 8 core/lib/Drupal/Core/TypedData/Validation/ExecutionContext.php \Drupal\Core\TypedData\Validation\ExecutionContext::addViolation()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/ExecutionContext.php \Symfony\Component\Validator\ExecutionContext::addViolation()

Adds a violation at the current node of the validation graph.

Note: the parameters $invalidValue, $plural and $code are deprecated since version 2.5 and will be removed in 3.0.

Parameters

string $message The error message:

array $params The parameters substituted in the error message:

mixed $invalidValue The invalid, validated value:

int|null $plural The number to use to pluralize of the message:

int|null $code The violation code:

Overrides ExecutionContextInterface::addViolation

File

vendor/symfony/validator/ExecutionContext.php, line 95

Class

ExecutionContext
Default implementation of {@link ExecutionContextInterface}.

Namespace

Symfony\Component\Validator

Code

public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null) {
  if (null === $plural) {
    $translatedMessage = $this->translator
      ->trans($message, $params, $this->translationDomain);
  }
  else {
    try {
      $translatedMessage = $this->translator
        ->transChoice($message, $plural, $params, $this->translationDomain);
    } catch (\InvalidArgumentException $e) {
      $translatedMessage = $this->translator
        ->trans($message, $params, $this->translationDomain);
    }
  }
  $this->globalContext
    ->getViolations()
    ->add(new ConstraintViolation($translatedMessage, $message, $params, $this->globalContext
    ->getRoot(), $this->propertyPath, func_num_args() >= 3 ? $invalidValue : $this->value, $plural, $code));
}