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

Created on 6 June 2023, about 1 year ago
Updated 26 March 2024, 3 months 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

Needs review

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

Production build 0.69.0 2024