Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
There are way too many theme functions / template files in core. Some are similar (if not identical) and should be consolidated.
Proposed resolution
We have two options:
- Remove theme_checkboxes() and call
theme('container')
instead (build a render array with'#theme' => 'container'
) - If we really do need a separate preprocess function for this, let's use
theme('container__checkboxes')
instead oftheme('container')
and add all our preprocess magic intotemplate_preprocess_container__checkboxes()
Remaining tasks
Decide which of the 2 options above to pursue, and do it.
User interface changes
None
API changes
Removal of theme_checkboxes
Related Issues
#2041825: Remove theme_radios() and call theme('container') instead
#1819284: [meta] Consolidate all form element container templates, and add theme_hook_suggestions
Comment | File | Size | Author |
---|---|---|---|
#33 | 2041845-33.patch | 5.19 KB | andypost |
#33 | interdiff.txt | 551 bytes | andypost |
Comments
Comment #1
ericduran CreditAttribution: ericduran commentedWorking on this.
Comment #2
ericduran CreditAttribution: ericduran commentedThis patch piggy backs on the work from #2041825: Remove theme_radios() and call theme('container') instead.
Once that gets in this is the only change requires.
Comment #4
Manuel Garcia CreditAttribution: Manuel Garcia commented#2152201: Convert theme_checkboxes() to Twig just got in, so theme_checkboxes is history. We are now using template_preprocess_checkboxes & core/modules/system/templates/checkboxes.html.twig
Attached a patch that removes the preprocess function and the twig file, and changes its #theme_wrappers to container.
Comment #6
Manuel Garcia CreditAttribution: Manuel Garcia commentedI believe we are loosing one css class
form-checkboxes
on this move towards using container.To restore it we should add:
$element['#attributes']['class'][] = 'form-'. $element['#type'];
to template_preprocess_container (within the// Special handling for form elements.
chunk).Otherwise we could also add it within
form_pre_render_checkbox($element)
function I suppose. However I believe adding it for every form element using container is a better approach.Comment #8
joelpittetI don't know for sure if this will work but, maybe you can set the theme_wrapper to 'container__checkboxes' and if the suggestions work with the preprocess functions you should be able to do template_preprocess_container__checkboxes to add in those extra classes.
Though that may need this:
#939462: Specific preprocess functions for theme hook suggestions are not invoked
Comment #9
mitokens CreditAttribution: mitokens as a volunteer commentedComment #10
andriyun CreditAttribution: andriyun at Skilld, Drupal Ukraine Community commentedComment #11
andypostComment #12
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer commentedRerolled and added the css class back in template_preprocess_container__checkboxes as per suggestion on #8.
Comment #14
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer commentedWell I don't know why those tests are failing, markup looks identical before and after...
Comment #15
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer commentedActualy, before:
After:
Comment #16
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer commentedOh g... my last two comments were meant to be for #2041825: Remove theme_radios() and call theme('container') instead
Comment #17
star-szrMy comment from #2041825-22: Remove theme_radios() and call theme('container') instead applies here as well.
Comment #32
andypostre-roll for 10.1
Comment #33
andypostfix for specific preprocess
Comment #34
smustgrave CreditAttribution: smustgrave at Mobomo commentedDidn't review yet
But seems there are failures in #33
Comment #35
andypostYes, 3 failed tests but results are not returned