-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Using TranslateableMessage with ExecutionContext::buildViolation #19704
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
Labels
Comments
@alexandre-daubois do you think PR should be reverted ? or adjusted Not sure this example works |
Actually I think the code should be updated 🙂 Let's see where it goes |
fabpot
added a commit
to symfony/symfony
that referenced
this issue
Apr 5, 2024
…d/addViolation()` (alexandre-daubois) This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Accept `Stringable` in `ExecutionContext::build/addViolation()` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony-docs#19704 | License | MIT `ConstraintViolationBuilder` accepts any stringable. We mentioned this [in the doc](https://symfony.com/doc/6.4/validation/translations.html) but it doesn't work as explained in the issue. I think `buildViolation()` could accept stringable, also given that `ExecutionContextInterface` defines the type as `string|Stringable` in the PHPDoc. Same for `addViolation()`. Commits ------- 394b514 [Validator] Accept `Stringable` in `ExecutionContext::build/addViolation()`
Symfony code was updated so this feature now works as explained in the docs. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding: https://symfony.com/doc/current/validation/translations.html
From: #19054 (comment)
From my experience in a project where I tried to use it like that it failed as the type declaration only allows "string" (https://github.com/symfony/validator/blob/6.4/Context/ExecutionContext.php#L157C21-L157C35) or so I miss something here?
Even TranslateableMessage implements "__toString" does not help as it would only return the template-message without resolving/translating it. (https://github.com/symfony/translation/blob/6.4/TranslatableMessage.php#L35)
I checked it for the version I used (6.4) but it seems to be the same for 7.X - if I missed something maybe we can clarify the example 🙏🏻
The text was updated successfully, but these errors were encountered: