Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295807

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

$
0
0

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

  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

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


Viewing all articles
Browse latest Browse all 295807

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>