- 🇮🇳India ankithashetty Karnataka, India
+1 to this issue.
Observations:
Create a view + use
<a href="https://www.drupal.org/project/views_infinite_scroll">views_infinite_scroll</a>
module (this requires Ajax to be enabled on view) +<a href="https://www.drupal.org/project/facets">facets</a>
module (even if the module is enabled on site, we need to not have to add a facet to this view)After deep analysis of this, found that this is happening due to this line https://git.drupalcode.org/project/facets/-/blob/3.0.x/src/Controller/FacetsViewsAjaxController.php?ref_type=heads#L51 from patch #3306634: Integrate with better_exposed_filters for AJAX → .
When the user clicks on 'load more' in the view:
page
key is stripped from query parameters inController/FacetsViewsAjaxController.php
- Because of this, we fail to get the 'page' data from .
- And due to this,
current_page
for the view will not get valid value here . It will always be 0 - And thus, these conditions will always fail
This is even observed for a view that has no facets added. It's a simple view with 'load more'. The facets module is enabled on the site. Due to this,
FacetsViewsAjaxController.php
will get fired on click of 'load more'. - 🇮🇳India ankithashetty Karnataka, India
Upgrading it to
major
to get some attention here as this could be a regression. We can downgrade it if it's a minor bug. - 🇮🇳India ankithashetty Karnataka, India
Have another update here:
CASE 1:
Looks like it works perfectly fine withviews_infinite_scroll
module +facets
module. The Ajax request is POST here.
CASE 2:
The problem is when we haveviews_infinite_scroll
module (this requires Ajax to be enabled on view) +facets
module (even if the module is enabled on site, we need to not have to add a facet to this view) + views_ajax_get module enabled & configured in the sites. Here, the views Ajax requests are changed to GET!
Observations:
- Including the steps mentioned in #3, noticed that all data like '
page
' exists only as query param and will not be part of the post request data as the views Ajax requests are changed to GET byviews_ajax_get
module - This
page
will be removed from query param by facets. - With
CASE 1
, we don't find this problem, as the required details likepage
exist in POST request which gets added back in core here /views/src/Controller/ViewAjaxController.php#L171
Tried and tested this on Drupal core: 9.5.11 and the latest compatible versions of all three modules.
- Including the steps mentioned in #3, noticed that all data like '
- 🇮🇳India ankithashetty Karnataka, India
Suggestions/workaround:
When you have a site with modules
views_infinite_scroll
,facets
andviews_ajax_get
:- Patch from here https://www.drupal.org/project/drupal/issues/956186#comment-14991435 📌 Allow AJAX to use GET requests Fixed for Drupal 9.5.x
- A small tweak in
facets/src/Controller/FacetsViewsAjaxController.php
file under functionfacetsRemoveQueryParams
protected function facetsRemoveQueryParams(Request $request) { if ($request->isXmlHttpRequest()) { // @todo replace hardcoded 'f' by facet setting. foreach (['f', 'page', 'fulltext'] as $key) { if ($request->query->has($key)) { if ($key === 'page' && !$request->request->has($key)) { $page = $request->query->get($key); $request->request->add([$key => $page]); } $request->query->remove($key); } } } }
- Status changed to Needs review
over 1 year ago 10:04am 5 October 2023 - Open on Drupal.org →Core: 10.1.x + Environment: PHP 8.1 & MySQL 8last update
over 1 year ago Waiting for branch to pass - 🇮🇳India ankithashetty Karnataka, India
Here is a patch for review.
As mentioned above, to work with a site having modules views_infinite_scroll, facets and views_ajax_get:
- Patch from here https://www.drupal.org/project/drupal/issues/956186#comment-14991435 📌 Allow AJAX to use GET requests Fixed for Drupal 9.5.x
- Along with the patch shared here.
Testing results:
Without both patches: - error
With just a core patch: - doesn't work
https://www.drupal.org/files/issues/2023-10-05/Screen%20Recording%202023... →With both the patches: - works as expected
https://www.drupal.org/files/issues/2023-10-05/Screen%20Shot%202023-10-0... → - Status changed to RTBC
over 1 year ago 2:02pm 13 October 2023 - 🇩🇪Germany mkalkbrenner 🇩🇪
Even if I would prefer to rewrite the entire parameter handling according to the changes symfony introduced, the patch looks good for now.
-
mkalkbrenner →
committed 50544b42 on 3.0.x authored by
ankithashetty →
Issue #3225764 by ankithashetty, mkalkbrenner, khadelk, joseph.olstad:...
-
mkalkbrenner →
committed 50544b42 on 3.0.x authored by
ankithashetty →
- Status changed to Fixed
over 1 year ago 2:06pm 13 October 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
9 months ago 1:12pm 9 May 2024 - 🇪🇸Spain david.carmona
Hi there,
I am reopening this issue because I have been able to verify that infinite scroll with facets using ajax in the view still does not work, even with the patch in #8. 🐛 Facets doesn't work correctly with views infinite scroll Active
I have been testing the patch and debugging the code, after adding a key 'page' to the request with the page number, we are still removing the key 'page' from the query:
$request->query->remove($key)
, this causes us to lose the results page that should be displayed from the query and does nothing after the ajax call is executed.Here I leave the refactored patch that I have been able to verify is working with:
- Drupal 10.2.5
- facets "3.0.0-beta1"
- views_infinite_scroll "2.0.2"
- AJAX enable on the view
- Facets widget for the view configured to be "view exposed filters"
- Also I have this patches applied to facets "3360426 - Updated php 8.2 compatibility": "
https://www.drupal.org/files/issues/2024-02-19/3360426-php8.2_compatibil... →
"
"3394955 - Use native views for url generation when using exposed filter facets": " https://www.drupal.org/files/issues/2023-10-20/3394955-10.patch → "
- 🇫🇷France PhilY 🇪🇺🇫🇷 Paris, France
Patch #14 works for me with:
- Drupal 10.3.6
- facets 3.0.0-beta1 + patch "3360426 - Updated php 8.2 compatibility"
- views_infinite_scroll 2.0.3
- AJAX enable on the view (block display)
Thanks