Media Library currentSelection not reset properly

Created on 5 March 2025, about 2 months ago

Problem/Motivation

When testing on πŸ’¬ Additional modal support Active , I find out that Drupal.MediaLibrary.currentSelection is not reset properly in https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/media...

Drupal.behaviors.MediaLibraryModalClearSelection = {
    attach() {
      if (!once('media-library-clear-selection', 'html').length) {
        return;
      }
      window.addEventListener('dialog:afterclose', () => {
        Drupal.MediaLibrary.currentSelection = [];
      });
    },
  };

Steps to reproduce

On core 11.1.3, standard profile:

  1. Enable Media Library module
  2. Add a media reference field on a content type
  3. Create or edit a node of this content type
  4. Add a media in the field
  5. Try to add another media

Result: "1 item selected" is displayed in the media library while no item is selected.
Expected result: "0 items selected" is displayed in the media library.

Proposed resolution

Fix found by @tocab.

Replace:

Drupal.MediaLibrary.currentSelection = [];

By:

Drupal.MediaLibrary.currentSelection.length = 0;

Remaining tasks

- create MR
- review
- merge

User interface changes

None

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

media system

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

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