While trying to reproduce #3169531: Warning error message on empty facet parameter, I stumbled over the problem that search_api_form_views_exposed_form_alter() didn’t actually find a corresponding facet source, so abandoned the attempt to include facet filters in the exposed form.
A bit of investigation showed me that, even though I had actual facets configured for the Views display in question, their facet source wasn’t actually saved in the storage. It seems like the entity is only saved when changes are made to its config – otherwise it’s included in the UI but never actually saved, even though facets are saved for it.
In my mind that’s inconsistent and makes it harder to interact with the module. I would have to add something like the attached patch to the Search API to make the “Remember facets when submitting” feature to keep working even when there is no facet source.
In my opinion (and with kind of an outside view on the Facets module, I admit), once a facet is saved for a facet source, the facet source should also be saved. (You could then also put a depdencency on the facet source into the facet config entity.)
If you disagree, then I’ll just add the patch to the Search API. But I wanted to discuss this alternative solution here first.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3174657-2--fix_remember_facets_option_in_edge_cases.patch | 1.42 KB | drunken monkey |
Comments
Comment #2
drunken monkeyComment #3
borisson_I agree, we figured this was a really good solution in the start. I can't remember why we did this, I think it was about not needing it at the start.
Autosaving the facet source when a facet is first created for it seems like a good solution, not sure about when we need to delete it. But I guess nothing is changed for that usecase.
Comment #4
drunken monkeyI now committed the patch to Search API, just to have this working for now. But would be great to have this fixed in Facets directly.
I don’t really see a reason to auto-delete it. If someone doesn’t need facets at all anymore, they should uninstall the module. Otherwise, they’ll need the facet source. Or, in rare cases, it might be unnecessary (as it represents an old index that isn’t used anymore, or something like that) – but what harm would that really do?