Fix Media library from Drupal core on user can add more than one image if he swipe to add them from the next page from the media library window

Created on 27 October 2021, about 3 years ago
Updated 21 June 2023, over 1 year ago

Problem/Motivation

For media library model, if we have a content type contains media field and this media field is limited to add only one image for this content type. If the user select the image from the media library and then swipe into the next page on the library, then the user can add more than one image.

Steps to reproduce

  1. Navigate into any content type has a media and limited to add only one image as site admin user.
  2. Click on "media" tab
  3. Try to add any image from the library, and then move into the next page in the library and try to add more images.
  4. Observe that user is still able to add more media from the next pages.

Proposed resolution

The user should not be able to add media from the next page in the media library if he reached the limit.

My findings are:

🐛 It is possible to overflow the number of items allowed in Media Library Fixed
More reported issues with videos and images in the duplicate issue
#3092536: Possible to select multiple images in a media field where only 1 value is accepted

Quick fix

The maintainer for the Media Library module Adam G-H (phenaproxima) is most likely will commit this fix into the next release of Drupal core.
🐛 It is possible to overflow the number of items allowed in Media Library Fixed

We could have the patch fix in Varbase Core before it been committed and released with Drupal Core.

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Add the 3059955-107.patch to fix drupal-9.2.x
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support on feature change/addition
  • ➖ User Guide Documentation support on feature change/addition
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Release varbase-9.0.3 , varbase_core-9.0.10

User interface changes

Having a message and a blocker of insert action is good

It's working well
After the fix:

Warning message
There are currently 2 items selected. The maximum number of items for the field is 1. Please remove 1 item from the selection.

1 was selected then on the upload of new image media file

Very good as not able to insert selected if they are out of the limit
After unchanging the extra old selected media item
Then we are able to insert

API changes

  • N/A

Data model changes

  • N/A
🐛 Bug report
Status

Fixed

Version

9.0

Component

Code

Created by

🇯🇴Jordan Delana_Alkurdi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • 🇧🇪Belgium Mookum

    This issue still persist when:

    • You add a media field restricted to upload 1 image, to a node.
    • Create a page , add one image and save this node
    • Go back edit this node, remove the image from the node: select some image + Add a new image from upload field: Save and insert.
    • 2 images are added, after that it fails to remove 1 image or save the node.

    Drupal version: 9.5.9

Production build 0.71.5 2024