8000 [HttpKernel] Hardcoded validation translation domain on RequestPayloadValueResolver · Issue #58170 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Hardcoded validation translation domain on RequestPayloadValueResolver #58170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
raphael-drdata opened this issue Sep 4, 2024 · 2 comments · Fixed by #58187
Closed

Comments

@raphael-drdata
Copy link

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));
@xabbuh
Copy link
Member
xabbuh commented Sep 5, 2024

Using validator.translation_domain here sounds sensible to me. PR welcome for the 7.2 branch.

@raphael-geffroy
Copy link
Contributor

Thanks @xabbuh ! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0