Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConstraintViolationBuilder.php

function ConstraintViolationBuilder::addViolation

Same name in this branch
  1. 11.1.x vendor/symfony/validator/Violation/ConstraintViolationBuilder.php \Symfony\Component\Validator\Violation\ConstraintViolationBuilder::addViolation()

Overrides ConstraintViolationBuilderInterface::addViolation

File

core/lib/Drupal/Core/Validation/ConstraintViolationBuilder.php, line 146

Class

ConstraintViolationBuilder
A constraint violation builder for the basic Symfony validator.

Namespace

Drupal\Core\Validation

Code

public function addViolation() : void {
    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));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal