Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
While editing the field settings for an image field, the Maximum and Minimum image dimensions should only allow for positive numbers. The attached patch adds the mentioned validation.
Comments
Comment #1
sulav CreditAttribution: sulav commentedComment #2
mgiffordDoes this error apply to D8 as well? I would assume so but haven't checked. If so it would need to be fixed there too.
Comment #3
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThis is not relevant for D9, because in D9 the input type "number" is used and #min and #max properties are set-up (so this is being checked by separate validations). In D7 we are only using input type "text".
D9:
D7:
The patch looks good, however there is a redundant check for
is_numeric()
:In this part the
$value
must be numeric, because in the first IF condition there is areturn;
in case the variable is not numeric.I have updated the patch (removed the redundant check) and added a simple test for these dimensions, as it seems like we did not have any until now.
Comment #5
yashingole CreditAttribution: yashingole at QED42 for Drupal India Association commentedComment #6
yashingole CreditAttribution: yashingole at QED42 for Drupal India Association commentedVerified and tested patch #3 on Drupal 7.x. Patch was applied successfully and looks good to me.
Testing steps:
1. Install 7.x
2. Navigate to admin/structure/types/manage/article/fields/field_image
3. Scroll Down to Image Resolution.
4. Set the values in negative.
5. Click on Save.
6. Changes are saved.
7. Apply the patch.
8. Navigate back to admin/structure/types/manage/article/fields/field_image
9. Set the resolution to negative.
10. Click on save.
11. Observe the error displayed.
Testing Result:
1. After applying the patch the error is displayed "Height and width values must be positive numbers."
Can be move to RTBC
Screenshots are attached for reference:
Comment #8
mcdruidGreat, thanks everyone!