Facets breaks all AJAX views that uses pagers even without facets

Created on 5 August 2023, almost 2 years ago

Problem/Motivation

The facets module breaks all AJAX views pagers even those that do not use facets.

Since the module overrides the base ajaxView method at

  public function onRouteAlter(RouteBuildEvent $event) {
    $collection = $event->getRouteCollection();
    if ($route = $collection->get('views.ajax')) {
      $route->setDefault('_controller', '\Drupal\facets\Controller\FacetsViewsAjaxController::ajaxView');
    }
  }

And the first line in the ajaxView method of the facets module is

$this->facetsRemoveQueryParams($request);

So it does not check if the view even has facets or not, just simply removes the "page" from all ajax views request.

This of course breaks all AJAX views that tries to paginate with AJAX.

Steps to reproduce

- Install the 3.x version of the facets module.
- Add any AJAX enabled view with a pager.
- The pager does not work.

Proposed resolution

Removing that one line
$this->facetsRemoveQueryParams($request);
fixes the issue, but I guess it was there for a reason.
So a better approach could be to detect if the views in question is a search api (or facet containing view) and then conditionally do the removal.
This is new in branch 3.x as I see so 2.x is not affected.

๐Ÿ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡ญ๐Ÿ‡บHungary nagy.balint

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024