Support facets 3.x facets exposed filters

Created on 10 February 2025, 6 months ago

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"), probably 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 that facets exposed filters support should come to this module (as opposed to Views Pretty Paths)
- Agreement on proposed resolution
- MR
- Review

User interface changes

Ability to configure pretty paths for facets exposed filters.

API changes

None?

Data model changes

Becomes inclusive of views filter plugins of type "facets_filter" in addition to config entities of type "facets_facet".

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States chrisolof

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

Merge Requests

Comments & Activities

  • Issue created by @chrisolof
  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    Support 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.

  • Merge request !20Add support for facets exposed filters β†’ (Open) created by chrisolof
  • Pipeline finished with Success
    6 months ago
    Total: 306s
    #430193
  • Pipeline finished with Success
    6 months ago
    Total: 303s
    #430204
  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    Test 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 the MR 20.

  • Pipeline finished with Success
    4 months ago
    #465948
  • Pipeline finished with Success
    4 months ago
    #465951
  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    In 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.

  • Status changed to Needs review 3 months ago
  • πŸ‡¬πŸ‡§United Kingdom c_archer Cumbria

    Tried this path, but it does not appear to be working, do I need to do anything?

  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    It 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.

  • πŸ‡¬πŸ‡§United Kingdom c_archer Cumbria

    Thanks mlncn, thats it working!

  • πŸ‡¬πŸ‡§United Kingdom effortDee

    Just wondering when this will roll out?

  • πŸ‡ΊπŸ‡ΈUnited States mlncn Minneapolis, MN, USA

    Thought i should report πŸ› Remove last facet fails Active as related to hereβ€” TLDR i think the "prettiest" paths (no query string at all, /view/category/foo-258 in the example above) seem a little incompatible with Facets via Better Exposed Filters or Views itself.

  • πŸ‡ΊπŸ‡ΈUnited States 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.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    +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?

  • πŸ‡§πŸ‡ͺBelgium StryKaizer Belgium

    Great 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.

    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 ;-)

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Thanks 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!

  • πŸ‡§πŸ‡ͺBelgium StryKaizer Belgium

    Facets 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!

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Beautiful, 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.

Production build 0.71.5 2024