Problem/Motivation

Media Library pagination fails inside WYSIWYG within Paragraphs
When clicking the pagination links in the Media Library modal, the modal content is replaced with the node edit page HTML instead of the next page of media items.

Steps to reproduce

  1. Install fresh Drupal (I am under 11.3.10)
  2. Enable the following modules: media, media_library, paragraphs.
  3. Import enough media items to enable pagination in the Media Library modal.
  4. Create a Paragraph type containing a formatted text field.
  5. Create a Content Type with a field referencing the Paragraph type.
  6. Create a node and add a Paragraph item.
  7. In the WYSIWYG editor, click the "Insert media" button.
  8. Click a pagination link in the Media Library modal (for example "Next page" or page 2).

Result: The modal content is replaced with the node edit page HTML.

Proposed resolution

The issue does not occur if one of the left-side tabs (Image, Document, Remote video, etc.) is clicked before using pagination.
As a workaround, I fixed the issue by automatically triggering a click on the first tab when the modal opens.

Issue fork drupal-3592366

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lionel rousseau created an issue. See original summary.

cilefen’s picture

lionel rousseau’s picture

Issue summary: View changes
tetranz’s picture

I don't think this is related to Paragraphs. I'm getting the same thing on a normal body field directly on a node with core 11.3.9.

I'm still looking into it.

tetranz’s picture

It only happens for me if the media library view uses a full pager. I think the default installation is a mini pager. It works correctly for me if I change it back to a mini pager.

I notice that the videos show a full pager.

lionel rousseau’s picture

@cilefen, no it is not related to #3461608: Problems with paragraphs widget when paragraph contains media widget.
I managed to reproduce the problem without paragraphs.

@tetranz Well spotted ! Changing pagination to a mini pager make it work properly on my website as well. You made my day!

tetranz’s picture

Disclosure: I used AI (Claude Code) to debug this and create the fix.

This seems to be a regression of https://www.drupal.org/project/drupal/issues/3122526.

A full pager on an AJAX enabled view does not need the use-ajax class added to the links. This is causing it to try to render the whole host form (such as node edit) inside the modal.

I'm sure this is not the only way to fix it but the way this patch works is to add a new #views_ajax_enabled render array key for the full pager. If PagerPreprocess sees this, it does not add the link attributes.

(My first Drupal MR with GitLab),

tetranz’s picture

Status: Active » Needs review
marcoscano’s picture

Title: media_library pagination fails » Full pager links in AJAX-enabled views are turned into modal dialog links inside modals, breaking pagination (e.g. in the media library)
Status: Needs review » Needs work

I think this is the correct direction, but it doesn't seem views-specific, we could have a more generic solution in place, IMO

tetranz’s picture

Yes #modal_dialog_links sounds good. I'll get back to it in a few days if nobody else does. I'm not sure about a change record.

marcoscano’s picture

Component: media system » ajax system

👍
Doesn't even seem media-specific either.. changing the component accordingly.

tetranz’s picture

Code changed as suggested. I'll look at doing a change report.

tetranz’s picture

Status: Needs work » Needs review

I've created a change record. https://www.drupal.org/node/3616887

I'm a little unsure about the branch and version.

Feel free to edit or suggest different wording.