Problem/Motivation
https://github.com/symfony/symfony/pull/32435 improved the Symfony Constraint violation message for the 'range' constraint. Previously the constraint would report 'This value should be %limit or more.' or 'This value should be %limit or less.' if the value was below the minimum or above the maximum. Now it will provide a 'This value should be between {{ min }} and {{ max }}.' message, unless either min or max is omitted.
I think this message is more helpful and should probably be adopted at some point, but will need the proper localization, and bc considerations.
Proposed resolution
For now, lets override the validator and force the current logic to continue in SF4
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff.3074645.5-7.txt | 939 bytes | mikelutz |
| #7 | 3074645-7.drupal.Account-for-changing-violation-message-in-symfony-range-constraint-between-SF3-and-SF44.patch | 3.31 KB | mikelutz |
Comments
Comment #2
mikelutzAdding custom validator.
Comment #3
gábor hojtsyHighly minor: missing dot at end of line. But I assume you just copied the Symfony code outright?
Comment #4
mikelutzI did, and fixed standards errors that I saw. For some reason my phpcs is erroring out right now locally (I think because I'm throwing all my dependencies out of whack going back and forth between SF3 and SF4). I just decided to throw it against testbot and fix anything else that I missed when I got the report. :-)
Comment #5
mikelutzphpcs didn't even complain about it after I got it working again. Anyway:
Comment #6
gábor hojtsySorry :(
Space.
Comment #7
mikelutzI did that on purpose, to not mix the period in the url, but this is better I think, and coder sniffer seems to like it.
Comment #8
gábor hojtsySuperb, thanks.
Comment #9
larowlanCould we just override the
$notInRangeMessageproperty on the constraint with the message we currently return or is that not possible with the logic changes?Comment #10
mikelutz@lawrolan - not logically possible.
Currently it says EITHER "$value must be $min or higher" or "$value must be $max or lower" depending on whether $value was too high or too low.
in 4.4, as long as min and max are both set it will say "$value must be between $min and $max"
So it's not just a message change, but also removing the logic to decide which of the two messages to display.
Personally, I like the new message, it's more useful, but I'm not sure how we introduce it, since any multi-lingual site would need to have it's translation files updated prior to the messaging change, There may be a policy on this, but I just don't know what it is.
The plan with this patch is to ensure consistency between D8 and D9 right now, and if we are able to update strings like this in D9, then we can do it in a controlled manner at a time of our choosing.
Comment #11
larowlanOk, should be good to put back to RTBC then
Comment #12
mikelutzMoving back to RTBC per #11
Comment #13
larowlanCommitted d4ae87e and pushed to 8.8.x. Thanks!