ImageItem::getUploadValidators() should be the source of truth for validating uploaded images

Created on 22 October 2018, over 5 years ago
Updated 10 July 2024, 8 days ago


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

  1. Install the Standard profile, and the Media Library module.
  2. Add a media field to a content type, referencing the Image media type.
  3. Edit the Image media type's source field ("Image") and set a maximum resolution of, say, 16x16.
  4. Start creating some content, and open the media library.
  5. Upload an image, bigger than the maximum allowed resolution, into the library.
  6. 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

Address feedback on merge request, 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


UI changes


Release notes snippet


๐Ÿ› Bug report

Needs work


11.0 ๐Ÿ”ฅ

Image systemย  โ†’

Last updated about 16 hours ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany stefan.korn Jossgrund

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates some issue and comment data are missing.

Production build 0.69.0 2024