Description
Symfony version(s) affected
6.3
Description
In \Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver::140 during the payload denormalization we map PartialDenormalizationException's errors into ConstraintViolations and we translate the messages with an hardcoded validators
domain.
So it does not take into account the possible override in framework.validation.
PS : I'll be glad to make the PR once the way to correct this is decided
How to reproduce
Override the translation_domain in framework.validation with a custom one and override the translations:
- This value was of an unexpected type
- This value should be of type {{ type }}
Create a controller with a MapRequestPayload Dto parameter and send a request with a wrongly typed property (send a string to a bool property for example). The violation message will not take your override message template into account.
Possible Solution
Do we really need to translate the message here ?
Can we pass the validator.translation_domain
param into this service (Not the same component) ?
Additional Context
$trans = $this->translator ? $this->translator->trans(...) : fn ($m, $p) => strtr($m, $p);
[...]
$message = $trans($template, $parameters, 'validators');
$violations->add(new ConstraintViolation($message, $template, $parameters, null, $error->getPath(), null));