-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[11.x] Adding minRatio & maxRatio rules on Dimension validation ruleset #52482
Conversation
…he Dimension rule test
2145545
to
c75165c
Compare
Please add a translation line for this and then mark ready for review again. 👍 |
@taylorotwell I took your meaning as wanting me add a more granular translation line for the added parameters, however based on the existing implementation of this Dimension rule, without a lot of additional changes we can only utilise the current translation line in validation.php 'dimensions' => 'The :attribute field has invalid image dimensions.', We can then use the parameters within the string, which are swapped out for their values in FormatsMessage parser: Currently I spent quite a while looking into & working on refactoring the Dimensions rule & related logic, to bring it inline with the granularity of validation messages afforded to us by the similar File rule, whilst also ensuring there are no breaking changes. It's possible & I have a patch with a lot of the work for an implementation, but will require further consideration, such as how the between rules will interact with the min/max, etc... Rather than go into it further & then to change the scope of this PR, I believe it would be wise to work on a refactor in a seperate PR that is independent of this one. Happy to hear your thoughts. |
Got it - thanks. |
This PR introduces the ability to set a minimum & maximum aspect ratio in the Dimension rule.
Currently the framework only supports fixed ratios within the rule, allowing restriction of aspect ratios to only the defined values, this would allow the user to set a range of aspect ratios that an image would have to fall within.
The premise for this was conceived whilst I was doing further work on the image upload feature for Pinkary. We are have been considering how to deal with very long images, such as screenshots of full webpages taken using devtools, where the aspect ratio is on the extreme end & it would be nice to be able to set a range to handle this through validation within the framework.
Currently we would need to write a custom rule or use a closure like so:
This PR introduces the ability to use it like so:
You could use only the minimum or maximum ratio alone, if you don't need upper or lower limits.
I also added a range method, that on evaluations adds a min_ratio and max_ratio constraint.
All 3 of the added methods would be a good edition to the Validation capabilities of the framework.
I have added tests to cover the addition of these methods to the Dimension ruleset.