Problem/Motivation
Facet summary with reset link enabled throws a fatal error on ajax calls, causing summary not being updated. This is the error thrown on server side:
InvalidArgumentException: The user-entered string 'http://absolute-url.com/my-path?f[]=facet-name:value' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 213 of /path/to/drupal/root/core/lib/Drupal/Core/Url.php).
Facet summary reset link processor is assumming we should link to the facet source url, but you could use a view block to display your results inside a node (for example). Not sure if this is related, but in such situation the url obtained is the absolute one, causing the fatal error.
Steps to reproduce
- Create a search api view with a block display and ajax enabled.
- Place the view block anywhere.
- Place some facet blocks and the facet summary on the same page.
- Filter the view by the facets.
- The summary won't update and you will find in the logs the error described above.
Proposed resolution
Do not try to point to the facet source url, but to the current path.
Remaining tasks
Review patch
User interface changes
none.
API changes
Data model changes
Comments
Comment #2
akalam commentedComment #3
akalam commentedComment #4
tbenice commentedThe patch isn't working for me. With it the facets dont appear until after a page refresh (with ajax on, and the page filtered). Same after reset.
Comment #5
kiseleva.t commentedI faced the same issue and reworked the patch.
Comment #6
analiam319@gmail.com commentedAfter updating to Drupal Core 9.3.3 and updating to the latest 2.0.x facets release, #5 stopped working for us. With #5 installed, the following error message was reported:
Re-worked the patch to use "getPathInfo" on the current main request instead of attempting to grab the facet source path. Patches available for both the 2.0.x and 8.x-1.x branches.
Comment #7
analiam319@gmail.com commentedApologies for the previous patch. I didn't notice that the reset link ended up pointing to /views/ajax instead of the actual page path.
Comment #9
analiam319@gmail.com commentedResolving automated tests. Very sorry about the subsequent messages!
Comment #10
nitebreedThis is exactly what I needed, works fine!
Comment #11
loopy1492 commentedSince upgrading from Facets 1.6 to 2.x, we are having this issue with ANY link, not just the reset link.
We have a view embedded on a page with facets embedded using the blocks interface in a sidebar. The view filters just fine when you're on the page, but if you try to take that link with its querystring and paste it into a browser's address bar, we get the error.
The (sanitized) url:
http://oursite.com/catalog?f%5B0%5D=competencies%3APersonal%20and%20Cust...
Comment #12
loopy1492 commentedWe downgraded and pinned to 1.8 until this is fixed. I have created a new issue for this.
Comment #13
mkalkbrennerComment #15
mkalkbrenner