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

When creating media in the media library, it is possible to overflow the number of items than allowed by the field

$
0
0

Problem/Motivation

Currently I use media library, media types and paragraphs to create content. There is a problem related to Allowed number of values, set to field.

How to reproduce:
I have media type image. It is used as Entity reference field attached to Paragraph. This will allow me to upload images on my nodes. I restricted media type to use image field with maximum number of values 1. Also set the entity reference field to maximum number of values = 1.
So when I am on node edit page and try add media, first I see existing media in the widget. When I select one media, all other become disabled and can not select them, which is OK.
The problem is that, when I select existing media and then click the form to upload new media, there is tab ADDITIONAL SELECTED MEDIA which saves previously selected media. When I upload the picture, it is added along side with previously selected and this cause problem to user limitations.
Pic. 1: Select existing media.
1

Pic. 2: Upload new image.
2

Pic 3: After form is submitted and two media are seelcted.
3

Pic. 4: Show that -1 media is selected.
4

Expected behavior:
Does not save media to additional selected when adding new media, when allowed number of values is 1.
Another resolution is to add option on form widget to disallow this functionality.

Proposed resolution

Show a warning message when the number of selected items exceeds the number of available items after adding new media.
Change the warning to an error message when the user tries to insert more than the allowed number of items.

Remaining tasks

  • Discuss solution
  • Write patch
  • UX Review
  • A11Y Review
  • Code review
  • Frontend framework manager review
  • Commit

User interface changes

Added error / warning messages to the media library.

Video of #21: https://www.drupal.org/files/issues/2019-07-17/media-library-exceeds-lim...

Screenshot of the warning after adding and exceeding the limit:
Warning message shown after exceeding the limit.

Screenshot of the warning after clicking 'Save and select':
Warning message shown after clicking 'Save and select'.

Screenshot of the error after clicking 'Save and insert' or 'Insert selected':
Warning message shown after clicking 'Save and insert'.

API changes

Data model changes

None

Release notes snippet


Viewing all articles
Browse latest Browse all 294605

Trending Articles



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