Problem/Motivation
If you have a media type that uses an image field as it source, and that field has a minimum/maximum resolution defined, the media library will completely ignore those constraints when uploading a new image into that media type.
Steps to reproduce
- Install the Standard profile, and the Media Library module.
- Add a media field to a content type, referencing the Image media type.
- Edit the Image media type's source field ("Image") and set a maximum resolution of, say, 16x16.
- Start creating some content, and open the media library.
- Upload an image, bigger than the maximum allowed resolution, into the library.
- You'll see that the upload proceeds without a hitch, even though the image is bigger than what's allowed.
Proposed resolution
The media library defers to the field's getUploadValidators()
method to determine how to validated uploaded files. As per the discussion between @phenaproxima and @alexpott in #33-35, it makes sense for the ImageItem
field type to override this method and provide validators that are specific to images, including resolution constraints, and have Media Library defer to that. This will provide a consistent API to determine image validation. While we're at it, we should also try to clean up other places that have had to manually set the validation, such as the Image module's integration with Quick Edit, REST's FileUploadResource, and JSON:API's TemporaryJsonApiFileFieldUploader.
Remaining tasks
Open a merge request implementing the proposed resolution, write tests, and commit.
API changes
None, really; ImageItem::getUploadValidators()
-- which it inherits from FileItem
-- will provide more specific validators, but this does not change the public API.
Data model changes
None.
UI changes
None.
Release notes snippet
TBD