Problem/Motivation
I would like to move to the facets 3.x exposed filters system while maintaining facets-pretty-paths-provided paths.
After evaluating the Views Pretty Paths module, I believe this is possible, but may be more straightforward if implemented here in Facets Pretty Paths due to the more polished routing strategy, existing integration with facets system and config, and more mature coder system and coders.
Steps to reproduce
N/A.
Proposed resolution
Expand support to facets exposed filters (views filter plugins of type "facets_filter"), offering the standard pretty paths config in the views exposed filter config (alongside the other facet config already there).
On incoming view + exposed filter query request (eg. "/view?category=258"), encode and redirect to the pretty path (eg. "/view/category/foo-258"). This should allow the pretty path to overtake the standard exposed filters path.
On incoming pretty path request, inject query params for any facets exposed filters into the current request object so the view can harvest them. No need to actually filter / apply anything at this stage because the view + facets exposed filters will handle this given the query parameter data.
Remaining tasks
- Agreement on proposed resolution
- MR
- Review
User interface changes
Ability to configure facets exposed filters to use pretty paths.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | facets_pretty_paths_3505618-support-facets-exposed-filters-mr-20-5.patch | 61.23 KB | chrisolof |
Issue fork facets_pretty_paths-3505618
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
chrisolofSupport added in the 3505618-support-facets-exposed-filters branch. Tested against a variety of facet filters with a variety of employed coders, single and multi-value selections. Seems to be working well at this point.
Pretty paths coder config is at the filter-level (it shows in the exposed filter options form). It is possible to combine pretty and regular query string facet filters (eg. "/view/category/foo-258?tag=33).
Filter order in the URL is currently just following the filter order already established in the view.
Still needs test coverage and likely some additional refinement - both hopefully coming in this week.
Comment #4
chrisolofTest coverage and small improvements added (some identified while adding the test coverage). This is now ready for review.
Attached is an immutable patch against 2.0.x representing the current state of MR 20.
Comment #5
chrisolofIn testing I found that the pretty path redirect response to the views exposed form submission was coming back with "no-cache" in the cache control header. Adding cacheability metadata to the pretty path redirect response seems to have solved the issue. This should improve performance on previously-requested facet filter combinations.
Attached is an immutable patch against 2.0.x representing the current state of MR 20.
Comment #6
c_archer commentedTried this path, but it does not appear to be working, do I need to do anything?
Comment #7
mlncn commentedIt works great!! Thank you chrisolof!
c_archer you need to do the configuration of Facet Pretty Paths on the View that has the facets, in the Filter criteria section, presented as (for an 'example' facet name) "Facet: Example (example)" — you need to press that name to configure
Pretty paths coder, not the Settings link as we all would usually expect.Comment #8
c_archer commentedThanks mlncn, thats it working!
Comment #9
effortdee commentedJust wondering when this will roll out?
Comment #10
mlncn commentedThought i should report #3528819: Remove last facet fails when using the Links exposed filter widget as related to here— TLDR i think the "prettiest" paths (no query string at all,
/view/category/foo-258in the example above) seem a little incompatible with Facets via Better Exposed Filters or Views itself.Comment #11
chrisolof@mlncn It looks like BEF builds its links from the current path (eg.
/view/category/foo-258), not the view's path (eg./view), and thus includes any active pretty path parts in all of the URLs it generates - even links that are supposed to remove selected options.In other words it doesn't appear that BEF links (including the links widget) are fully-compatible with what we're doing here, yet. If BEF used the view's path (
/view) as the starting point for its links, instead of the current path (/view/category/foo-258), I believe its links would become fully compatible.You might consider proposing a patch to BEF that changes
Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetBase::getExposedFormActionUrl()to pull the starting URL from$this->view->getUrl()instead of the current request. In a quick test in my dev environment I just confirmed that little change in BEF does indeed resolve the BEF links widget issue you describe.I should also mention that moving to the checkboxes/radios BEF widget is another way to overcome the deselection issue, but that may not be right for your site.
Comment #12
ressa+1 for the MR, thanks @chrisolof! Your updated code works well with Facets 3 and Better Exposed Filters (BEF) using the "Exposed filter widget" set to "Checkboxes/Radio buttons".
I hope it can get committed before too long. Perhaps you could consider applying to become a co-maintainer, to help move this great improvement along?
Comment #13
strykaizerGreat work,
However, in Facets 3, we are now avoiding to do custom, not facet-related, features anymore.
This is another example of something we should offload to a more global solution, which works for every views exposed filter (not only facets, and not only search-api-based views).
That is why my preferred solution is fixing this in "Views Pretty Paths module" (similar to how we also moved the functionality from "Facets summary" to "Views Exposed Filters Summary", which benefits everyone).
I understand that "Views Pretty Paths module" does not (yet) support the coders plugin system. We should probably contribute that part too in that module.
Contributing this to the "Views Pretty Paths" module is high on my todo list, I will probably work on it next month.
But for people who need this functionality now: feel free to use the patch above.
The "facets summary" module will probably not change much anymore, as we are focusing on global solutions. So the patch should be working for a long time without too much re-rolls ;-)
Comment #14
ressaThanks for clarifying the situation and plan @strykaizer, and that we can probably safely use the MR here for the time being.
Just out of curiosity, will Facets Pretty Paths eventually be totally replaced by Views Pretty Paths? Perhaps a short "Future plans" section with a sentence or two from your comment could be added on the project page? Should this issue be set to "Postponed"? (I added a short update in the Issue Summary).
It sounds great that you may take a look at getting this feature in "Views Pretty Paths" module soon, and I (and probably the rest of the users here) will be ready to test an MR when it's ready. Have a great day!
Comment #15
strykaizerFacets pretty paths will stay available for users using Facets 3 with Facet entities (Facets as a block), and Facets 2 users.
However, the recommended way in Facets 3 is now to use "Facets Exposed Filters".
People using "Facets Exposed Filters" will not need this module anymore in the future.
I updated the project summary to clarify. Thx!
Comment #16
ressaBeautiful, thanks @strykaizer!
The description on the project page is an invaluable resource, both for finding the correct and best solution in the first place, assess its features and limitations, and review future plans, and with your addition, all bases are covered.
I am using the new Facets 3 methods for my latest project, and it works really well. Managing all filters via a single block is a big improvement, and being able create filters directly in the View (and not on their own page) is another improvement. So making the Facets ecosystem modules more globally reusable, turns out to be a correct strategic decision. So thanks for your great efforts with Search API and Facets in Drupal, I very much appreciate it.
Comment #18
strykaizerI looked into views_pretty_paths, but lack the time rewriting this to a global solution
So I changed mind about #13 , lets just support this feature in facets_pretty_paths.
I like how this patch only works when ajax is disabled, which is great, as ajax enabled views should use the GET params instead.
Thanks for contributing all!
Comment #21
strykaizerComment #22
ressaThanks everyone for fixing this! Perhaps @mlncn and @strykaizer should be credited for reviewing, committing, and so on? Thanks!