Closed (duplicate)
Project:
Drupal core
Version:
11.x-dev
Component:
media system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 May 2020 at 23:04 UTC
Updated:
30 Oct 2025 at 13:20 UTC
Jump to comment: Most recent
Comments
Comment #2
oknateThis may be a duplicate of #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items'
Comment #4
phenaproximaOn the face of it, this sounds like a major bug. Escalating accordingly until we determine it's not as big of a deal.
Comment #5
xld commentedI've come across this issue in a context where I need to filter what users can choose from the media library based on the page they are on.
For the sake of debugging I have tried to remove all filters and the sorting only leaving my one and only contextual filter which I really need but with no luck.
Haven't had a chance to look into the code to see where my contextual gets lost between the
/admin/structure/views/view/media_library/edit/widget_tablewhere it works and the select widget on the node page where it doesn't.Any idea on how to overcome this until it gets fixed would be much appreciated.
Comment #6
gregroper commentedI am currently experiencing a similar issue since 8.7.14 and have subsequently updated to 8.9.6 where the issue still happens:
I have a contextual filter configured for the widget display in the media library views, whereby the media is filtered by Authored By and the User ID is provided as a default value (User ID from logged in user) not the URL.
When this contextual filter is applied I cannot use any exposed filters, sort or pagination, as on reloading the form after applying filters (or paging to 2nd page) the selected media image can't be inserted and an uncaught AJAX parse error is thrown (not logged in Drupal):
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /media-library?name=&sort_by=created&destination=/admin/content&media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bportal_image%5D=portal_image&media_library_selected_type=portal_image&media_library_remaining=1&media_library_opener_parameters%5Bfield_widget_id%5D=field_image_s_%3A-field_portal_fields-0-subform&media_library_opener_parameters%5Bentity_type_id%5D=paragraph&media_library_opener_parameters%5Bbundle%5D=image_only&media_library_opener_parameters%5Bfield_name%5D=field_image_s_&media_library_opener_parameters%5Bentity_id%5D=74&hash=F61Z_kJE84DnIJZNRHoZ6dtSPFWMJLzL0SsTksSg8_s&ajax_form=1&views_display_id=widget
StatusText: OK
This issue occurs when adding media to a content type field on a node or even when trying to add default image for the paragraph type that uses the Media Entity Reference field type.
However, without the contextual filter applied, everything works as expected - exposed sorts, filters and pagination all work fine and any image can be selected and successfully inserted.
core 8.9.6
nginx/1.16.1
php7.3.17
5.5.5-10.3.25-MariaDB-1:10.3.25+maria~focal
Comment #7
dystopianblue commentedEncountering the same problem as noted by gregroper above. I added the "Media: Authored by" contextual filters to both media widget views and set them to "User ID from logged in user". Initially, the media library displayed correctly on first load, but after toggling between the grid and table views, the views displayed without the contextual filters enforced. I wonder if it's because the contextual filters aren't being passed into the url parameters of the grid/table links, eg.
admin/content/media-widget-table/image/all?media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bimage%5D=image&media_library_selected_type=image&media_library_remaining=10...Comment #9
chikeI have same setup as @dystopianblue, I added the 'Media: Authored by' contextual filter with setting 'Provide default value' and 'User ID from logged in user'.
When an authenticated user opens the Library the contextual filter is respected in the default 'Grid' view but if you click on the 'Table' view the filter is ignored and if you click back to the Grid it will loose the initial respect and will also ignore the filter. At this point the filter is totally ignored.
To get going in the meantime I removed the headers.
core 8.9.7
Comment #10
weseze commentedHaving the same issue...
@chike: Could you explain "To get going in the meantime I removed the headers." What exactly did you do?
Comment #11
chike@weseze I removed the HEADER section from the view, entirely, thereby removing the Grid and Table buttons.
Comment #12
weseze commentedAlso did that, did not work for me... (core 8.9.14)
Comment #13
chikeYou should add a contextual filter 'Authored by' to filter 'User ID from logged in user', for the 'Widget' and 'Widget (table) displays.
Comment #16
akafitty commentedThis exactly identifies the problem we are experiencing with the Media module. In our situation, we added a contextual filter to only display images that have been added by the logged in user.
On a node edit page, when you click 'Add media' the insert button does nothing and the browser reports AJAX errors if you're selecting media after performing a search or after you apply any filters inside the Media widget. You can select and insert media on page 1 of the widget but the minute you modify the search results the insert fails.
Removing the contextual filters from the widget view solves the problem but then all media results are shown and in our situation that is not ideal.
Any help is greatly appreciated.
Comment #17
akafitty commentedQuick update on this… I believe I've found a workable solution here: https://www.drupal.org/project/drupal/issues/3283692
Inside that thread is some custom code that, when added to a custom module, will only display media uploaded by the current logged in user, in all media library widgets. Seems to work so far from the limited testing I've done. I've removed previously added contextual filters.
cheers,
ev
Comment #19
anna d commentedI had issue with contextual filter on media library view.
Was solved with adding query condition in custom module.
Comment #20
solimanharkas commented#19 works for me! Thanks
Comment #22
herved commentedI think I just stumbled on this issue.
It looks like the form ID changes because it is built in
\Drupal\Core\Form\FormBuilder::getFormIdaccording to the views arguments being passed, We get the following form IDs:- initially (modal loaded): views_form_media_library_widget_image
- click apply filters or pager: views_form_media_library_widget_image_[some additional args]
- click insert selected: views_form_media_library_widget_image
FormBuilder::buildFormchecks theform_idto build the ajax response and throw FormAjaxException.But since the
form_iddoesn't match, drupal sends an HTML response instead of JSON, which results in a "parsererror" in JS.The main suspect here to me is
MediaLibraryUiBuilder::buildMediaLibraryViewwhich passes only 1 argument to the view:$args = [$state->getSelectedTypeId()];Just unsure what to do/how to solve at this point.
Any thoughts?
Edit: I think I will solve it with a service decorator for now (extending MediaLibraryUiBuilder, overriding buildMediaLibraryView).
Comment #23
herved commentedUpdate: #3401726: MediaLibraryUiBuilder service does not properly allow additional contextual filter arguments sounds like the proper fix, works perfect for me.
Could some of you test as well so we could close this issue here as duplicate?
Thanks
Comment #24
pavlosdanI tested the MR in #3401726 as well and it seems to resolve the issue.
Comment #25
tobiasbYes, #3401726: MediaLibraryUiBuilder service does not properly allow additional contextual filter arguments resolves the issue.