Problem/Motivation
If you attempt to add contextual filters to the core media library, they will correctly be used when the library results are initially loaded, but are not passed to the view itself, so internal display links (the "grid" and "table" buttons) get URLs built that ignore the contextual arguments.
Steps to reproduce
Add/edit the any content type
Add media reference field, in manage form display of content type: select
'media library' display
Then edit the view of core media libray (widget display):
https://your_site_url/admin/structure/views/view/media_library
Then add a contextual argument to view displays (for eg. wigets , widget table), such as "media: authored by" and select "user ID from logged in user" as the default value or either can add fixed uid for test purpose
Add node, try to add media , Click on one of the display buttons in the header, either grid or table, you 'll find contextual filter not work as view will show all media instead of just your own.
Actual behaviour
Click on one of the display buttons in the header, either grid or table, and the view will refresh to show all media instead of just your own. This is wrong.
Expected behaviour
when try to upload image using a media library widget, then view that is loaded only shows the media your user has created. This is correct.
Proposed resolution
Replace the current build call in buildMediaLibraryView()
return $view_executable->buildRenderable($display_id, $args, FALSE);
with
return $view_executable->buildRenderable($display_id, [], FALSE);
I did initially try this with $view_executable->args
, but that seems to be redundant and passing []
has exactly the same effect. Current behaviour which passes through just the entity type argument ($args
) stops any other contextual filters from working securely when the view is rendered. The $view_executable->execute($args)
call a few lines earlier already does the full argument calculations for all contextual filters.
Add tests