Passing theme suggestions to radio and checkbox children

Created on 17 August 2017, over 7 years ago
Updated 20 May 2024, 7 months ago

When attempting to provide theme suggestions for radios and checkboxes via HOOK_theme_suggestions_alter the suggestions are not passed down into the individual radio and checkbox children.

For example with twig debugging switched on and a suggestion of $suggestions[] = $hook . '__minimal'; in HOOK_theme_suggestions_alter the following is output:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'fieldset' -->
<!-- FILE NAME SUGGESTIONS:
   x fieldset--minimal.html.twig
   * fieldset.html.twig
-->

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'radios' -->
<!-- FILE NAME SUGGESTIONS:
   x radios--minimal.html.twig
   * radios.html.twig
-->

However, these suggestions do not get passed down to the children (form_element, form_element_label and input__radio):

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form_element' -->
<!-- FILE NAME SUGGESTIONS:
   x form-element.html.twig
-->

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'form_element_label' -->
<!-- FILE NAME SUGGESTIONS:
   x form-element-label.html.twig
-->

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'input__radio' -->
<!-- FILE NAME SUGGESTIONS:
   x input--radio.html.twig
   * input.html.twig
-->
🐛 Bug report
Status

Closed: works as designed

Version

11.0 🔥

Component
Theme 

Last updated about 1 hour ago

Created by

🇬🇧United Kingdom intrafusion Edinburgh, UK

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India yash.rode pune

    Hi, I was trying to reproduce this problem, but I was not able to do so.
    I created and installed a Custom module with

    /**
     * Implements hook_theme_suggestions_alter().
     */
    function my_mod_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
        $suggestions[] = $hook . '__minimal';
    }

    and tested if the form-element-label.html.twig is replaced with the new form-element-label--minimal.html.twig.
    The new template is overriding the original template. below is the snapshot showing the same


    As it can be seem from the above image, I have added

    minimal

    to form-element-label--minimal.html.twig. Also it is loading form-element-label--minimal.html.twig instead of form-element-labe.html.twig.

    TLDR either the issue does not exist anymore as the issue is quite old or I am missing something in the steps to reproduce.

  • Status changed to Postponed: needs info 8 months ago
  • 🇺🇸United States smustgrave

    Thanks for testing that @yash.rode!

    @intrafusion or anyone could you confirm the issue still exists? If so update the issue summary.

  • Status changed to Closed: works as designed 7 months ago
  • 🇬🇧United Kingdom intrafusion Edinburgh, UK

    Would appear that somewhere between 8.5 & 11 this has been rectified

Production build 0.71.5 2024