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

  1. Create a new Media Type, with a source of Image
  2. Open the "Manage Fields" page and edit the Image field
  3. Set minimum or maximum image dimensions
  4. Save the field
  5. Edit another entity type's fields
  6. Add a Media field
  7. Include the newly created Media Type as an allowed option
  8. Save the field
  9. Create a new instance of that entity
  10. 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

Issue fork drupal-3226629

Command icon 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

simon_tma created an issue. See original summary.

simon_tma’s picture

StatusFileSize
new2.22 KB

This is the patch we've applied to our projects that appears to work as needed.

simon_tma’s picture

StatusFileSize
new2.22 KB

Updated patch to handle media types that aren't named "Image"

longwave’s picture

Thanks 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

longwave’s picture

simon_tma’s picture

Having ImageItem::getUploadValidators() include validators for the image resolution would make the patch needed for the Media Library widget much nicer (would just need FileUploadForm::createFileItem() to return an ImageItem for 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.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

frontmobe’s picture

StatusFileSize
new2.72 KB

Adding the patch posted in #3 for use with Drupal 9.4.x here:

_utsavsharma’s picture

StatusFileSize
new718 bytes
new2.29 KB

Tried to fix CCF for #10.

simon_tma’s picture

StatusFileSize
new2.23 KB

Updated patch for Drupal 10.1.0

bmartijn’s picture

#12 works for me on Drupal 10.1.1

gauravvvv’s picture

StatusFileSize
new2.3 KB

I have attached patch for 11.x as patch #12, doesn't apply any more so not adding interdiff.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Appears there is no test coverage.

luispimentellopes’s picture

StatusFileSize
new2.37 KB

Previous patches didn't work with 10.3, adding a compatible patch.

simon_tma’s picture

StatusFileSize
new2.13 KB

Replacing the patch from #18, removing the header block that prevents it from being applied

frontmobe’s picture

StatusFileSize
new2.3 KB

The most recent patch did not apply to cores 10.3.1, I attached a rerolled patch.

pooja_sharma made their first commit to this issue’s fork.

pooja_sharma’s picture

I have created MR against 11.x , however working test coverage part , so keeping it in NW.

mornel’s picture

Hi,

I tried the latest patches including MR #23 but none of them works on my D11.

  • Drupal: 11.0.5
  • MariaDB: 10.11.9
  • Php: 8.3.12
nikhil_110’s picture

Assigned: Unassigned » nikhil_110
nikhil_110’s picture

StatusFileSize
new2.41 KB
new2.95 KB
new145.26 KB

Attached 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.

nikhil_110’s picture

Assigned: nikhil_110 » Unassigned
mornel’s picture

Attached 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.

Yes, patch #26 does it job. Thank you nikhil_110.

f.tendi’s picture

StatusFileSize
new2.95 KB

Hi, attached a new version of the patch working with Drupal 11.3

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

yorickdv’s picture

Correct 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