public function ExecutionContext::addViolation

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

@api

Parameters

string $message The error message.:

array $params The parameters substituted in the error message.:

mixed $invalidValue The invalid, validated value.:

integer|null $pluralization The number to use to pluralize of the message.:

integer|null $code The violation code.:

Overrides ExecutionContextInterface::addViolation

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/ExecutionContext.php, line 90

Class

ExecutionContext
Default implementation of {@link ExecutionContextInterface}.

Namespace

Symfony\Component\Validator

Code

public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null) {
  if (null === $pluralization) {
    $translatedMessage = $this->translator
      ->trans($message, $params, $this->translationDomain);
  }
  else {
    try {
      $translatedMessage = $this->translator
        ->transChoice($message, $pluralization, $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, $pluralization, $code));
}