-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add ThisableMessage
#53098
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
base: 7.4
Are you sure you want to change the base?
[Validator] Add ThisableMessage
#53098
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
I believe you can already do something a bit more complex using the ExpressionValidator (which is much more advanced than only |
ExpressionValidator does not allow you to customize the error message with {{ this. }} |
what about this one? |
Here too, the message remains unchanged. |
It would be nice... but I think it would be a big refactoring job for the team to rethink how violations and their parameters are generated Because at the moment, all variables implemented as {{ value }} are defined in their validator (IsNullValidator for example). |
02d792b
to
1298333
Compare
ThisableMessage
Hello !
I really like the way you can place assertions on Symfony :
But if our need becomes a little more complex, as when we want to validate several Person at once :
If we validate this object with some valid Persons and others not, we'll have a large list of exceptions containing "This value should be equal to 20" with the value path. That's enough to meet many needs, and twig with the form component displays them correctly.
But my need was simply to display "This value should be equal to 20 for the person whose first name is Émile." and I couldn't find any elegant way of doing it.
So I've coded this Assertion which makes it possible to do :
If you find this feature interesting, I'd be happy to write the documentation and the changelog, but I might need a little help to improve the test and source code. And maybe "ThisableMessage" is a name that can evolve.
I use it to validate CSVs containing hundreds of rows over dozens of columns, and adding this assertion had no noticeable effect on performance.
Thank you,