Problem/Motivation
Some background first, since this issue is nuanced:
In Views, there's a Drupal setting "views.ajax_path" that stores the path to the "views.ajax" route. In "views/js/ajax_view.es6.js" the current URL's query parameters are appended to the "views.ajax_path", and that is used to construct the Drupal.ajax settings that elements like pagers use.
This works great if an AJAX view exists on a page on load, i.e. If you have a View that uses the "Page" display and exists on /my-view, visiting /my-view?bar=baz will mean that all subsequent Views AJAX requests will include "?bar=baz".
The problem here is that if you're at another path like /my-route, and load the View via AJAX with a path like"/my-view?bar=baz", the "bar=baz" parameters will be lost, because /my-route does not include those query parameters.
This negatively affected #2962525: Create a field widget for the Media library module because we wanted to pass query parameters to the View when loading it in a modal, but realized that those query parameters were lost on subsequent AJAX requests.
Proposed resolution
When the view is initially constructed, store the query parameters in "drupalSettings.ajaxViews.views_dom_id:*", maybe in a property like "ajax_path". Then use this in "Drupal.views.ajaxView" when constructing the Drupal.ajax settings for each view.
Remaining tasks
Write a patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #3
suit4 commentedI just have to report, that the function
media_library_views_post_render()creates a wrong ajax_path if the Drupal installation is running on http://localhost/my-site-name
This setup leads to an ajax action path similar to this one:
/my-site-name/my-site-name/admin/content/media-widget?media_library_widget_id=field_hero_media-&media_library_allowed_types%5Bimage%5D=image&media_library_allowed_types%5Bremote_video%5D=remote_video&media_library_allowed_types%5Bvideo%5D=video&media_library_remaining=1&_wrapper_format=drupal_modal&ajax_form=1&_wrapper_format=drupal_ajaxObviously, this results in an 404 ajax response.
Maybe this can be fixed when working on this block of code:
A workaround for the time being:
add local domain, so you can access your Drupal installation via http://my-site-name.local
Comment #4
seanbWe actually don't need this anymore now the approach for the media library has changed in #3020716: Add vertical tabs style menu to media library.
The AJAX path code is removed in #2981044-37: Unify the grid/table views of the media library. I think we can close this issue when #2981044: Unify the grid/table views of the media library lands.
Comment #5
seanbComment #6
panchoI think we should leave the issue open. Even if media library won't need it anymore, contrib might still hit this issue. Don't know if it's a bug though or a missing, yet expected feature.
Comment #7
seanbTurns out I was wrong, we did actually still need/use that code and did not remove it in #2981044: Unify the grid/table views of the media library.
Comment #9
vflirt commentedHey, can you help me out to get local setup with the issue and I can work on it.
Comment #12
berdirPossible duplicate of #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items'
Comment #17
azinck commentedFYI the workaround in media_library_views_post_render introduced this bug: #3308719: Media Library views fail to reset pager when filters are applied