-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
[Validator] Allow to use translation_domain false for validators and to use custom translation domain by constraints #48852
Conversation
Hey! To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done? Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review. Cheers! Carsonbot |
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilderInterface.php
Outdated
Show resolved
Hide resolved
0882fa4
to
a554b34
Compare
Hey! I think @norkunas has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
Friendly ping @nicolas-grekas, how can I provide BC for this situation ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about your questions for BC 😬
src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Outdated
Show resolved
Hide resolved
If I change
to
in the
So someone could extends the ValidatorBuilder and override the setTranslationDomain with the "old" signature. If I change
to
in the |
e2e8a1a
to
ce641ab
Compare
25987d1
to
b8b0300
Compare
b8b0300
to
c3595b7
Compare
I change my PR to be BC and resolved your request changes @nicolas-grekas :) |
Tests failure doesn't seem related |
c3595b7
to
4413a70
Compare
344f044
to
501f7dd
Compare
Would you have time to take a look/review this @nicolas-grekas @fabpot ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter validator.translation_domain
is also used in FormTypeCsrfExtension
and in UploadValidatorExtension
so I suppose we should make them accept false
also?
How do you expect to disable translation otherwise for builders?
Or maybe this change is not needed for builders?
src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilderInterface.php
Outdated
Show resolved
Hide resolved
If this (#48852 (comment)) is a BC break, it cannot be done for Builder then. So validator.translation_domain cannot be set to false, because of the
It's maybe not needed for Builder then ; I removed it. The second BC break (#48852 (comment)) is more annoying ; any way to avoid it but still allowing calling setTranslationDomain(false) ? |
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Show resolved
Hide resolved
Passing a custom translation domain is already possible through |
src/Symfony/Component/Validator/Context/ExecutionContextInterface.php
Outdated
Show resolved
Hide resolved
May I ask why you need this feature BTW? |
Sure.
But currently, there is no way to use the Validator features without the translator.
would be perfect |
So, we don't need to change addViolation, right? |
Changing
To me |
what's the issue with still processing them through the translator? |
Can't the same argument be used for the option The issue with having them processed by the translator are:
The second point is annoying when you look for all the missing translations, either
|
src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php
Show resolved
Hide resolved
please have a look at this concern please also add needed changelog+upgrade entries
should we update the template so that they use strtr? |
I'm not sure we should support I also think we could avoid changing the signature of If we do these 2 things, it simplifies the code a lot as the ExecutionContext does not need to change anymore and we can add |
This might be a good idea since it would be consistent with the review of this PR and with the behavior of the IdentityTranslator. But I would say it's better to scope this to another PR (that I can do after if wanted).
I agree
Since @nicolas-grekas was thinking the same, I reverted this change. |
src/Symfony/Component/Validator/Context/ExecutionContextFactory.php
Outdated
Show resolved
Hide resolved
10ae991
to
0c6d62e
Compare
0c6d62e
to
e9216b1
Compare
I squashed the commit and rebase the branch. Is everything ok on this PR @nicolas-grekas ? :) |
LGTM yes, thanks. Can you please add some tests? |
2bb2601
to
7a3491d
Compare
Sure, I added one. Do you think this is enough or is there more to test ? |
…to use custom translation domain by constraints
7a3491d
to
aef515f
Compare
Thank you @VincentLanglet. |
….disable_translation` option (alexandre-daubois) This PR was merged into the 7.3 branch. Discussion ---------- [FrameworkBundle][Validator] Add `framework.validation.disable_translation` option | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | Todo Follow-up of #48852 and after a suggestion of `@javiereguiluz` [here](symfony/symfony-docs#18325 (comment)). Commits ------- 98ce3f0 [FrameworkBundle][Validator] Add `framework.validation.disable_translation` config
Currently it's possible to write
but it's not allowed to pass a custom translation_domain (or to disable the translation by passing
false
).Adding a third parameter would allow this. (And changing the
?string
type tostring|false|null
).Wdyt about this feature ? How can we make it fully BC ?