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
- Enable Media Library module
- Add a media field to a content type, under Manage form display set widget to Media library
- Add or edit a node for that content type, for that media field click Add media to open the media library
- Below the media entities, click right on the pager
- Type something in the Name search, click Apply filters
- 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.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3272629
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:
- 3272629-media-library-widget
changes, plain diff MR !7392
Comments
Comment #2
kelly.m.jacobs commentedComment #3
cilefen commentedComment #4
heni_deepak commentedI 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
Comment #6
imclean commentedThis 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?
Comment #7
cilefen commentedI don’t fully understand the question.
Comment #8
abhijith s commentedApplied 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:

After patch:

RTBC +1
Comment #9
imclean commented@cilefen #7:
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.
Comment #10
cilefen commentedI was asking what exactly this question means:
Comment #11
imclean commentedThe issue version is 9.4.x-dev. I was wondering if the fix could be included in 9.3.x-dev.
Comment #12
cilefen commentedYes, because 9.3 still gets bug fix releases.
Comment #13
imclean commentedThanks.
Comment #14
gordon commentedThis 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.
Comment #15
imclean commented9.3.x bug fix support ended June 1.
@gordon, have you had a chance to look into it further?
Comment #17
qusai taha commentedThe issue exists on Drupal 10.1 and the patch fixed the issue.
Thank you!
Comment #18
smustgrave commentedWill need test coverage.
Comment #19
loon commentedThe issue is reproduced on Drupal 10.1.6, the patch fixed the issue
Comment #21
alexpottCrediting @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.
Comment #23
alexpottCreate a merge request with test coverage of the bug. Nice find!
Comment #24
smustgrave commentedBehat\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
Comment #25
catchComment #29
nod_Committed 55d41da and pushed to 11.x. Thanks!
Comment #31
catchComment #33
longwaveReverted this from 10.2.x as the test has consistently failed since it was added.