Unverified Commit 20496dd2 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3029540 by mikelutz, catch, alexpott, larowlan, Gábor Hojtsy: [Symfony...

Issue #3029540 by mikelutz, catch, alexpott, larowlan, Gábor Hojtsy: [Symfony 4] Sub class \Symfony\Component\Validator\ConstraintViolation and use that in \Drupal\Core\TypedData\Validation\ExecutionContext::addViolation()
parent 202ad58e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\EntityDisplayBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolation;
use Drupal\Core\Validation\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\ConstraintViolationListInterface;

+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
use Drupal\Core\Entity\Plugin\Validation\Constraint\CompositeConstraintBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\Validator\ConstraintViolation;
use Drupal\Core\Validation\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ConstraintViolationList;

+1 −1
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Drupal\Core\TypedData\Validation;

use Drupal\Core\Validation\ConstraintViolation;
use Drupal\Core\Validation\TranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Util\PropertyPath;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
+1 −1
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Drupal\Core\TypedData\Validation;

use Drupal\Core\Validation\ConstraintViolation;
use Drupal\Core\Validation\TranslatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
+62 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Validation;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation as SymfonyConstraintViolation;

/**
 * ConstraintViolation subclass to handle markup in messages.
 *
 * In symfony 4, the message in a violation is typecast to string.  This class
 * allows for a markup object to be used instead.
 */
class ConstraintViolation extends SymfonyConstraintViolation {

  /**
   * The violation message, may be markup or a string.
   *
   * @var \Drupal\Component\Render\MarkupInterface|string
   */
  private $originalMessage;

  /**
   * Constructs a ConstraintViolation object.
   *
   * @param \Drupal\Component\Render\MarkupInterface|string $message
   *   The violation message.
   * @param string $messageTemplate
   *   The raw violation message.
   * @param array $parameters
   *   The parameters to substitute in the raw violation message.
   * @param mixed $root
   *   The value originally passed to the validator.
   * @param string|null $propertyPath
   *   The property path from the root value to the invalid value.
   * @param mixed $invalidValue
   *   The invalid value that caused this violation.
   * @param int|null $plural
   *   The number for determining the plural form when translating the message.
   * @param mixed $code
   *   The error code of the violation.
   * @param \Symfony\Component\Validator\Constraint|null $constraint
   *   The constraint whose validation caused the violation.
   * @param mixed $cause
   *   The cause of the violation.
   */
  public function __construct($message, $messageTemplate, array $parameters, $root, $propertyPath, $invalidValue, $plural = NULL, $code = NULL, Constraint $constraint = NULL, $cause = NULL) {
    $this->originalMessage = $message;
    parent::__construct($message, $messageTemplate, $parameters, $root, $propertyPath, $invalidValue, $plural, $code, $constraint, $cause);
  }

  /**
   * Returns the violation message.
   *
   * @return \Drupal\Component\Render\MarkupInterface|string
   *   The violation message
   */
  public function getMessage() {
    return $this->originalMessage;
  }

}
Loading