Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37e840a

Browse files
[Validator] Fix translation of AtLeastOneOf constraint message
1 parent 069b83c commit 37e840a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Symfony/Component/Validator/Constraints/AtLeastOneOfValidator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use phpDocumentor\Reflection\Types\ContextFactory;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\ConstraintValidator;
17+
use Symfony\Component\Validator\Context\ExecutionContext;
18+
use Symfony\Component\Validator\Context\ExecutionContextFactory;
1619
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1720

1821
/**
@@ -31,7 +34,11 @@ public function validate($value, Constraint $constraint)
3134

3235
$validator = $this->context->getValidator();
3336

34-
$messages = [$constraint->message];
37+
// Build a first violation to have the base message of the constraint translated
38+
$baseMessageContext = clone $this->context;
39+
$baseMessageContext->buildViolation($constraint->message)->addViolation();
40+
$baseViolations = $baseMessageContext->getViolations();
41+
$messages = [(string) $baseViolations->get(\count($baseViolations) - 1)->getMessage()];
3542

3643
foreach ($constraint->constraints as $key => $item) {
3744
if (!\in_array($this->context->getGroup(), $item->groups, true)) {

0 commit comments

Comments
 (0)