2

I'm using Search API with Facets and a view to display the results. Everything works as expected but I would like to have a reset button per facet, that could be used as a "Show all" button.

For the moment I'm using facets_preprocess_facets_item_list(&$variables) to create an extra item on the top of every list, eg.

  • Facet 1 : Region
    All regions, Region 1, Region 2, ...
  • Facet 2 : Financial support
    All financial supports, Financial support 1, Financial support 2, ...
  • Facet 3 : Status
    All statuses, Status 1, Status 2, ...
  • Facet 4 : Sector
    All sectors, Sector 1, Sector 2, ...

To construct the "All ..." links, I'm getting the parameters of the current page and I clean up the filters. For example if the user clicks on the "All financial supports" [facet 2] link while the current page parameters are
../organizations?[facet 1]organizations%5B0%5D=region%3A18&[facet 2]organizations%5B1%5D=financial_support%3A1&[facet 3]organizations%5B2%5D=status%3A10&[facet 4]organizations%5B3%5D=sector%3A28
the parameters become
../organizations?[facet 1]organizations%5B0%5D=region%3A18&[facet 2][facet 3]organizations%5B2%5D=status%3A10&[facet 4]organizations%5B3%5D=sector%3A28

It works, but I'm not conviced that this is the best solution because I've managed to dramaticaly slow down the display of the view and, well... it's not very elegant.

Do you know if there is another, more Drupalish solution to implement a reset button per facet? Thank you in advance for your help.

1

Have you tried the following?

  1. Navigate to the facet setting page (/admin/config/search/facets/facet_name/edit)
  2. under widget set it to List of Checkboxes or List of Links (not sure what you are using)
  3. Within List of Checkboxes setting or List of Links Setting, there should be an option Show Reset Link.
  4. Enabled it and it will show a Reset Text input box where you can add Reset Facet or whatever you need.
  5. Apply other settings and click save.

list of checkboxes for facets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.