- Issue created by @scotwith1t
- 🇨🇦Canada plousia
Same issue here, actually my theme picks up and uses the modified template but it stops the links from being converted to checkboxes and throws the same error as in the original report.
- 🇨🇦Canada plousia
If you use the more specific template suggestion with facet type + facet name, it solves this problem. E.g. facets-item-list--searchbox-checkbox--FACETNAME.html.twig. That may be a pain if you have multiple searchbox facets, but it's a workaround at least till this issue is fixed.
- 🇧🇪Belgium Freya
Having the same issue with version 2.0.6
Solution from comment #3 🐛 Cannot customize facets-item-list--searchbox-checkbox.html.twig in theme Active also worked for me - First commit to issue fork.
- 🇧🇪Belgium andreasderijcke Antwerpen / Gent
andreasderijcke → changed the visibility of the branch 3365166-cannot-customize-facets-item-list--searchbox-checkbox.html.twig to hidden.
- 🇧🇪Belgium andreasderijcke Antwerpen / Gent
andreasderijcke → changed the visibility of the branch 3365166-cannot-customize-facets-item-list--searchbox-checkbox.html.twig to hidden.
- 🇧🇪Belgium andreasderijcke Antwerpen / Gent
andreasderijcke → changed the visibility of the branch 3365166-cannot-customize-facets-item-list--searchbox-checkbox.html.twig to active.
- Merge request !196Issue 3365166: Prevent facets items being run twice through... → (Open) created by andreasderijcke
- 🇧🇪Belgium andreasderijcke Antwerpen / Gent
The problem is due to the way hook_preprocess_HOOK works, is triggered for detected templates:
- For the default templates facets-item-list--searchbox-checkbox.html.twig and facets-item-list--searchbox-links.html.twig, the hook facets_preprocess_facets_item_list() (which adds title) is not triggered.
- For a copy of the templates in the active theme, the hook facets_preprocess_facets_item_list() is triggered. This causes the title to appear but also results in 2 passes of the template variables through template_preprocess_item_list(). It's the second pass that results in PHP errors.
- When creating a facet specific variant of a templates in the active theme, hook facets_preprocess_facets_item_list() is not triggered for the template, resulting in the default situation.
Screenshot below showing the hooks for these situations. The scheduler hook doesn't affect the output of the widget, but its presence emphasizes the hook callstack differences depending on the template specificity.
The MR fixes these issues by:
- Syncing the facets_searchbox_widget_preprocess_facets_item_list__searchbox_checkbox() and facets_searchbox_widget_preprocess_facets_item_list__searchbox_links() with facets_preprocess_facets_item_list() for the missing title
- Preventing double processing of the variables by template_preprocess_item_list()
- As a bonus, the cache debugging output has been added to facets-item-list--searchbox-checkbox.html.twig and facets-item-list--searchbox-links.html.twig.
- Status changed to Needs review
8 months ago 3:19pm 26 March 2024 - 🇧🇪Belgium andreasderijcke Antwerpen / Gent
As @Freya points out, the issue is also present in 2.0.x as the code is basically the same, so the patch from the MR also works on that branch.
- 🇨🇦Canada morgandawe
I can confirm the patch https://git.drupalcode.org/project/facets/-/merge_requests/196.patch corrects the issue for me on the 2.0.x branch.
- 🇮🇳India bibliophileaxe
Thanks for the patch @andreasderijcke and @morgandawe for the review. After applying this patch, we can customize the twig file in our theme. The missing title also reappears which is a nice bonus.