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.
Pic. 2: Upload new image.
Pic 3: After form is submitted and two media are seelcted.
Pic. 4: Show that -1 media is selected.
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 solutionWrite patchUX ReviewA11Y 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:
Screenshot of the warning after clicking 'Save and select':
Screenshot of the error after clicking 'Save and insert' or 'Insert selected':
API changes
Data model changes
None