- πΊπ¦Ukraine Anna D
I had issue with contextual filter on media library view.
Was solved with adding query condition in custom module./** * Implements hook_views_query_alter(). */ function mymodule_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { if ($view->id() == 'media_library') { $media_ids = [..Get needed ids..]; // If media ids is empty provide 0 id. $media_ids = $media_ids ?? [0]; $media_content_data = $query->setWhereGroup('AND'); $query->addWhere($media_content_data, 'media_field_data.mid', $media_ids, 'IN'); } }
- π©πͺGermany solimanharkas Hamburg
#19 π Media Library view widgets do not support contextual filters Active works for me! Thanks
- π§πͺBelgium herved
I think I just stumbled on this issue.
It looks like the form ID changes because it is built according to the views arguments being passed, e.g:
- 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_imageFormBuilder::buildForm
checks theform_id
to build the ajax response and throw FormAjaxException.
But since theform_id
doesn'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::buildMediaLibraryView
which passes only 1 argument to the view:
$args = [$state->getSelectedTypeId()];
Just unsure what to do/how to solve at this point.
Any thoughts? - π§πͺBelgium herved
Update: π MediaLibraryUiBuilder service does not properly allow additional contextual filter arguments Needs work 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 - π¨π¦Canada pavlosdan
I tested the MR in #3401726 as well and it seems to resolve the issue.