Problem/Motivation

In the media library widget, if you navigate in the pager, type something in the Name search, and click Apply filters, the pager will stay on the same page. This can lead to issues, such as no media items showing if there aren't any search results past the current page.

This issue only seems to exist in the widget and widget_table displays. The Media Library page returns to the first page on search.

Steps to reproduce

  1. Enable Media Library module
  2. Add a media field to a content type, under Manage form display set widget to Media library
  3. Add or edit a node for that content type, for that media field click Add media to open the media library
  4. Below the media entities, click right on the pager
  5. Type something in the Name search, click Apply filters
  6. The pager will stay on the same page, sometimes showing no media entities depending on the search

Proposed resolution

Return to first page when Apply filters is clicked. Or, if this is the result of a bug in the media_library module code, search for the origin of the problem.

Remaining tasks

Create a patch for drupal/core.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork drupal-3272629

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

kelly.m.jacobs created an issue. See original summary.

kelly.m.jacobs’s picture

cilefen’s picture

Status: Active » Needs review
heni_deepak’s picture

I have fellow these steps (before applying the patch)

Replace the Image field with the media image field in Article type.
I have added almost 40 Images.

I have filtered by name and tested the pager. Yes, it stays on the same page.

After apply patch

it's working.

Great

lpeidro made their first commit to this issue’s fork.

imclean’s picture

This is a pretty major usability issue as it renders the media library search almost useless. The patch resolves the issue nicely.

Should this be applied to 9.3.x?

cilefen’s picture

I don’t fully understand the question.

abhijith s’s picture

StatusFileSize
new11.58 MB
new19.51 MB

Applied the media_library_pager_fix.patch on 9.4.x and it fixes the issue.The contents appear in search after applying this patch in both grid and table views of the media library widget.

Before patch:
before

After patch:
after

RTBC +1

imclean’s picture

@cilefen #7:

I don’t fully understand the question.

  • When using the media library widget to select media there is a filter option to search by "Name".
  • When you have many pages of media items you may browse to another page, such as page 2.
  • When you're on page 2 and you do a "Name" search for something the pager stays on page 2.
  • If the above search doesn't return 2 pages of results then the search will produce no results.

Desired behaviour

Results of the search are displayed from page one.

To achieve this, the above patch resets the pager to the first page when searching the media library.

cilefen’s picture

I was asking what exactly this question means:

Should this be applied to 9.3.x?

imclean’s picture

The issue version is 9.4.x-dev. I was wondering if the fix could be included in 9.3.x-dev.

cilefen’s picture

Yes, because 9.3 still gets bug fix releases.

imclean’s picture

Version: 9.4.x-dev » 9.3.x-dev

Thanks.

gordon’s picture

This fixes the issue but I do think this is a little kludgy.

If I run this via the media library widget and I will get this issue as descibed above. However if I run the view via the Views UI I do not get the issue that I see via the media library widget. it will return to the first and act as expected.

This patch does fix the problem but I think that there is a bigger underlying problem with is not being resolved in the widget.

imclean’s picture

Version: 9.3.x-dev » 9.4.x-dev
Status: Needs review » Needs work

9.3.x bug fix support ended June 1.

@gordon, have you had a chance to look into it further?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

qusai taha’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Needs work » Needs review

The issue exists on Drupal 10.1 and the patch fixed the issue.
Thank you!

smustgrave’s picture

Version: 10.0.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Will need test coverage.

loon’s picture

The issue is reproduced on Drupal 10.1.6, the patch fixed the issue

alexpott credited azinck.

alexpott’s picture

Crediting @azinck from the duplicate issue #3308719: Media Library views fail to reset pager when filters are applied

#3323574: Pager not working correctly in AJAX view with exposed filters is also interesting as that could go hand in hand with this fix.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Create a merge request with test coverage of the bug. Nice find!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Behat\Mink\Exception\ElementNotFoundException : Link with id|title|alt|text "Next page" not found.

Ran tests locally as I couldn't run in gitlab due to roles.

But also manually testing the change appears to solve the issue being described

catch’s picture

  • nod_ committed 55d41da8 on 11.x
    Issue #3272629 by kelly.m.jacobs, alexpott, Abhijith S, imclean,...

  • nod_ committed 58d58134 on 10.3.x
    Issue #3272629 by kelly.m.jacobs, alexpott, Abhijith S, imclean,...

  • nod_ committed 09af9754 on 10.2.x
    Issue #3272629 by kelly.m.jacobs, alexpott, Abhijith S, imclean,...
nod_’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 55d41da and pushed to 11.x. Thanks!

catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

longwave’s picture

Version: 10.2.x-dev » 10.3.x-dev

Reverted this from 10.2.x as the test has consistently failed since it was added.