Enable grouping for checkboxes and radio buttons

Created on 18 May 2014, about 10 years ago
Updated 1 June 2024, 26 days ago

As of today, grouping is only possible for select lists, not for checkboxes and radio buttons. In form.inc, options buttons get flattened out.
If you read this thread: #1878292: Add grouping by Vocabulary / Content type / Bundle for check boxes / radio buttons widget you can see that grouping for checkboxes and radio buttons is a legitimate feature request for entity reference fields.
I believe this can be accomplished by doing the following:
1/ setting optgroups property to TRUE for options_buttons in function _options_properties() of modules/field/modules/options.module file. This prevents #options from being flattened out.
But the presentation layer does not handle grouping for checkboxes and radios... so:
2/ modify function form_process_checkboxes in includes/form.inc to actually handle grouping. I've only tested for checkboxes so far but I believe the same can be done for radio buttons in form_process_radios.
3/ finally for the system not to throw an illegal choice error at form validation, we actually need to flatten the options before validation process the same way its done for select lists right now in function _form_validate of include/form.inc

In order not to break already existing Drupal sites, I suggest we wrap steps 1 and 3 in conditional statement based on either :
- a variable in settings.php
- or maybe more a Drupal variable (variable_get) configurable in the UI that wouldn't need to be copied manually and maybe forgotten each time we need to update settings.php.

Note that modifications in 2) would not affect current Drupal sites since all the grouping code would only be executed for Arrays() but all options would still be flattened out... so no array, no new behavior.

Could this be added to the Drupal 7 core or is it too late? I will of course provide my code as soon as it is more complete.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Form 

Last updated about 7 hours ago

Created by

🇫🇷France Nicolas Bouteille

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

Production build 0.69.0 2024