Problem/Motivation
If an image-based media type is configured to have restrictions on the image dimensions, the Media Library form field does not enforce these limits.
Steps to reproduce
- Create a new Media Type, with a source of Image
- Open the "Manage Fields" page and edit the Image field
- Set minimum or maximum image dimensions
- Save the field
- Edit another entity type's fields
- Add a Media field
- Include the newly created Media Type as an allowed option
- Save the field
- Create a new instance of that entity
- In the Media Library widget, click the "Add media" button
The bug is now visible. The image upload field doesn't show the restrictions on the dimensions of the image, though it does have the correct file extensions and file size restrictions shown.
Uploading an image that cannot be resized to fit in the required dimensions does not cause an issue. Uploading an image that can be resized does not result in the image being resized.
If going through the Media gallery (/admin/content/media), the image dimension restrictions are correctly enforced.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 3226629-29.patch | 2.95 KB | f.tendi |
| #26 | 3226629-Screenshot.png | 145.26 KB | nikhil_110 |
| #26 | 3226629-26.patch | 2.95 KB | nikhil_110 |
| #26 | interdiff-23-26.txt | 2.41 KB | nikhil_110 |
| #20 | 3226629-20.patch | 2.3 KB | frontmobe |
Issue fork drupal-3226629
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
simon_tma commentedThis is the patch we've applied to our projects that appears to work as needed.
Comment #3
simon_tma commentedUpdated patch to handle media types that aren't named "Image"
Comment #4
longwaveThanks for the report and patch.
I think this is a duplicate of #3008292: ImageItem::getUploadValidators() should be the source of truth for validating uploaded images, which I found linked from the closed @todo issue mentioned in the code: #2988215: Use #element_validate for the upload element in the MediaLibraryUploadForm
Comment #5
longwaveComment #6
simon_tma commentedHaving
ImageItem::getUploadValidators()include validators for the image resolution would make the patch needed for the Media Library widget much nicer (would just needFileUploadForm::createFileItem()to return anImageItemfor images).I'm not particularly happy with how my patch couples the validation logic into
FileUploadForm, so would definitely prefer the cleaner, more reusable approach in #3008292.Comment #10
frontmobeAdding the patch posted in #3 for use with Drupal 9.4.x here:
Comment #11
_utsavsharma commentedTried to fix CCF for #10.
Comment #12
simon_tma commentedUpdated patch for Drupal 10.1.0
Comment #14
bmartijn commented#12 works for me on Drupal 10.1.1
Comment #15
mlncn commentedComment #16
gauravvvv commentedI have attached patch for 11.x as patch #12, doesn't apply any more so not adding interdiff.
Comment #17
smustgrave commentedAppears there is no test coverage.
Comment #18
luispimentellopesPrevious patches didn't work with 10.3, adding a compatible patch.
Comment #19
simon_tma commentedReplacing the patch from #18, removing the header block that prevents it from being applied
Comment #20
frontmobeThe most recent patch did not apply to cores 10.3.1, I attached a rerolled patch.
Comment #23
pooja_sharma commentedI have created MR against 11.x , however working test coverage part , so keeping it in NW.
Comment #24
mornel commentedHi,
I tried the latest patches including MR #23 but none of them works on my D11.
Comment #25
nikhil_110 commentedComment #26
nikhil_110 commentedAttached patch against Drupal 11.x-dev.. also added inter diff file #22 MR in file_validate_image_resolution is deprecated so don't work i have change and added new.
Comment #27
nikhil_110 commentedComment #28
mornel commentedYes, patch #26 does it job. Thank you nikhil_110.
Comment #29
f.tendi commentedHi, attached a new version of the patch working with Drupal 11.3
Comment #31
yorickdv commentedCorrect me if i'm wrong, but I think this issue might be a a duplicate of #3008292. We might want to work in 1 central issue