Media library integration does not work well for fields that accept multiple values

Created on 17 October 2023, about 1 year ago
Updated 2 February 2024, 10 months ago

Problem/Motivation

In πŸ“Œ Add media library support Fixed an integration with Media Library was introduced. For a media reference field that accepts multiple values the integration is not working well (yet).

We have a media field in which we can upload multiple images. This works fine with the default widget. A system dialog opens and we can upload multiple images at once. We have customers that (want to) upload a lot of large image files at once and they might encounter issues (e.g. server limits). To better support this it would be nice if we can use the File Resumable Upload module.

If we enable the dev version the File Resumable Upload module, including the work from issue πŸ“Œ Add media library support Fixed , the multiple file upload is replaced by the interfaces provided by this module. But then both the drop area and the system dialog via the Browse button only support one file at a time.

When I edit \Drupal\file_resup\Form\FileFormAlterBase::formAlter() and hardcode the $cardinality to -1 I can upload multiple image files at once. The upload works fine, but only the first image is added to the media library.

Steps to reproduce

- Install Drupal 9.5.x
- Enable Media Library (and its dependencies)
- Make sure a media type supporting file uploads exists (file, image)
- Create an entity type with a media reference field accepting multiple values and allow a file media type to be referenced
- Make sure the set the media library widget for the field
- Verify that multiple files can be uploaded / referenced at once
- Add and enable the File Resumable Upload module
- See that now only a single file can be uploaded / reference at once

Proposed resolution

The Media Library module itself calculates the number of available slots on the media reference field to determine the cardinality for the file upload field in the widget. We might be able to do the same.

We also need to fix that multiple files can be added as references directly after uploading. No idea yet about how to fix it.

Remaining tasks

-
-
- Review MR
- Merge MR

User interface changes

Multiple files can be uploaded in the media library widget with File Resumable Upload enabled.

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands ricovandevin

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024