Cannot customize facets-item-list--searchbox-checkbox.html.twig in theme

Created on 6 June 2023, over 1 year ago

Problem/Motivation

There may be 2 issues at play here, happy to break that out if needed. Initially, I was just trying to get the facet title to show up as I have it configured and it works as expected for other facet widgets, but wasn't showing up here. Was going to just try and fix in my own copy of the template but copying the default template for that widget to my theme throws an error.

Steps to reproduce

- Copy template facets-item-list--searchbox-checkbox.html.twig to your custom theme
- Fatal error: "attributes" is an invalid render array key in /var/www/html/web/core/lib/Drupal/Core/Render/Element.php on line 98

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇺🇸United States scotwith1t Birmingham, AL

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

Merge Requests

Comments & Activities

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

  • Pipeline finished with Failed
    8 months ago
    Total: 770s
    #129674
  • 🇧🇪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:

    1. 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
    2. Preventing double processing of the variables by template_preprocess_item_list()
    3. 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
  • 🇧🇪Belgium andreasderijcke Antwerpen / Gent
  • 🇧🇪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.

Production build 0.71.5 2024