diff -u b/facets.install b/facets.install --- b/facets.install +++ b/facets.install @@ -7,6 +7,7 @@ use Drupal\facets\Entity\Facet; use Drupal\facets\Entity\FacetSource; +use Drupal\block\Entity\Block; /** * Convert facets on Search Api facet sources to use the display plugin. @@ -153,14 +154,14 @@ /** * Update facet blocks configuration with a block id used for AJAX support */ -function facets_update_8005() { +function facets_update_8006() { $query = \Drupal::entityQuery('block') ->condition('plugin', 'facet_block', 'STARTS_WITH') ->execute(); foreach ($query as $block_id) { - $block = \Drupal\block\Entity\Block::load($block_id); - $block->get('settings', $configuration); + $block = Block::load($block_id); + $configuration = $block->get('settings'); $configuration['block_id'] = $block_id; $block->set('settings', $configuration); $block->save(); diff -u b/js/dropdown-widget.js b/js/dropdown-widget.js --- b/js/dropdown-widget.js +++ b/js/dropdown-widget.js @@ -68,7 +68,8 @@ // Go to the selected option when it's clicked. $dropdown.on('change.facets', function () { - window.location.href = $(this).val(); + var a = $($ul).find("[data-drupal-facet-item-id='" + $(this).find(':selected').data('drupalFacetItemId') + "']"); + $(a).trigger('click'); }); // Append empty text option. diff -u b/js/facets-views-ajax.js b/js/facets-views-ajax.js --- b/js/facets-views-ajax.js +++ b/js/facets-views-ajax.js @@ -31,17 +31,18 @@ // Loop through all facets $.each(settings.facets_views_ajax, function (facetId, facetSettings) { - // Get the View for the current facet. - var view = $('.view-id-' + facetSettings.view_id + '.view-display-id-' + facetSettings.current_display_id).first(); - var dom_id_start = 'js-view-dom-id-'; - var current_dom_id = $.map(view.attr('class').split(' '), function (v, i) { - if (v.indexOf(dom_id_start) > -1) { - return v.slice(dom_id_start.length, v.length); + var view, current_dom_id, view_path; + $.each(settings.views.ajaxViews, function (domId, viewSettings) { + // Check if we have facet for this view. + if (facetSettings.view_id == viewSettings.view_name && facetSettings.current_display_id == viewSettings.view_display_id) { + view = $('.js-view-dom-id-' + viewSettings.view_dom_id); + current_dom_id = viewSettings.view_dom_id; + view_path = facetSettings.ajax_path; } }); - if (typeof Drupal.views.instances['views_dom_id:' + current_dom_id] === 'undefined') { + if (view.length != 1) { return; } @@ -50,7 +51,7 @@ $('[data-drupal-facets-summary-id=' + facetSettings.facets_summary_id +']').children('ul').children('li').once().click(function (e) { e.preventDefault(); var facetLink = $(this).find('a'); - updateFacetsView(facetLink, current_dom_id); + updateFacetsView(facetLink, current_dom_id, view_path); }); } // Update view on facet item click @@ -58,7 +59,7 @@ $('[data-drupal-facet-id=' + facetId + ']').find('.facet-item').each(function (index, facet_item) { $(facet_item).children('a').click(function (e) { e.preventDefault(); - updateFacetsView($(this).attr('href'), current_dom_id); + updateFacetsView($(this).attr('href'), current_dom_id, view_path); }); }); @@ -66,7 +67,7 @@ if ($(facet_item).hasClass('item-list__dropdown')) { $(facet_item).unbind( "change.facets" ); $(facet_item).on('change.facets', function () { - updateFacetsView($(this).val(), current_dom_id); + updateFacetsView($(this).val(), current_dom_id, view_path); }); } }); @@ -77,21 +78,21 @@ }; // Helper function to update views output & Ajax facets. - var updateFacetsView = function(href, current_dom_id) { + var updateFacetsView = function(href, current_dom_id, view_path) { // Refresh view var views_parameters = Drupal.Views.parseQueryString(href); var views_arguments = Drupal.Views.parseViewArgs(href, 'search'); var views_settings = $.extend( - {}, - Drupal.views.instances['views_dom_id:' + current_dom_id].settings, - views_arguments, - views_parameters + {}, + Drupal.views.instances['views_dom_id:' + current_dom_id].settings, + views_arguments, + views_parameters ); // Update View. var views_ajax_settings = Drupal.views.instances['views_dom_id:' + current_dom_id].element_settings; views_ajax_settings.submit = views_settings; - views_ajax_settings.url = '/views/ajax?q=' + href; + views_ajax_settings.url = view_path + '?q=' + href; Drupal.ajax(views_ajax_settings).execute(); diff -u b/src/Plugin/facets/facet_source/SearchApiDisplay.php b/src/Plugin/facets/facet_source/SearchApiDisplay.php --- b/src/Plugin/facets/facet_source/SearchApiDisplay.php +++ b/src/Plugin/facets/facet_source/SearchApiDisplay.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Core\Extension\ModuleHandler; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\facets\Exception\Exception; use Drupal\facets\Exception\InvalidQueryTypeException; use Drupal\facets\FacetInterface; @@ -388,6 +389,7 @@ 'view_id' => $view->id(), 'current_display_id' => $view->current_display, 'view_base_path' => ltrim($view->getPath(), '/'), + 'ajax_path' => Url::fromRoute('views.ajax')->toString(), ]; $build['#attached']['library'][] = 'facets/drupal.facets.views-ajax'; $build['#attached']['drupalSettings']['facets_views_ajax'] = [