Problem/Motivation
I noticed after a Drupal 10 -> Drupal 11 upgrade, I'm seeing an extra border/padding around radio buttons used in some of my custom forms. This appears to be because fieldgroup.module.css is no longer being attached to the page.
In Drupal 10, this was a part of system.libraries.yml here. So it was being attached on all pages. This is missing in Drupal 11.
However, CompositeFormElementTrait.php still adds the .fieldgroup class to fieldsets. See here.
In my example, when using '#type' => 'radios' in a custom form, Drupal wraps the radios in a fieldset, which contains the .fieldgroup class. Now since fieldgroup.module.css is no longer attached to the page, we are missing this styling:
.fieldgroup {
padding: 0;
border-width: 0;
}
Steps to reproduce
- Set Stark as the default theme.
- Disable CSS aggregation.
- Visit
/user/1/editin the browser. - Check for
fieldgroup.module.cssin the page's<head>.
Proposed resolution
Attach the core/drupal.fieldgroup library in CompositeFormElementTrait::preRenderCompositeFormElement().
Remaining tasks
User interface changes
Before:

After:

Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Stark_Before_Fix.png | 75.13 KB | shubhamgoel |
| #7 | Stark_After_Fix.png | 57.42 KB | shubhamgoel |
Issue fork drupal-3633898
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cilefen commentedComment #5
shubhamgoel commentedHi Team,
I changed preRenderCompositeFormElement() in
CompositeFormElementTrait.phpto attach core/drupal.fieldgroup whenever it adds the fieldgroup class. Radios and checkboxes with a title or description should now get fieldgroup.module.css on the page.Please review and merge the MR https://git.drupalcode.org/project/drupal/-/merge_requests/17642/diffs.
Comment #6
smustgrave commentedWould be good to get screenshots from a standard drupal install of this issue.
Comment #7
shubhamgoel commentedHi Team,
I captured before/after screenshots of the Roles checkboxes on /user/1/edit, on a fresh standard install of this branch. The bug shows up when the site uses Stark. It doesn't show up in Default Admin, the theme a standard install uses.
Comment #8
smustgrave commentedStark is meant to be bare so I'm wondering if this is a bug actually.
Comment #9
dcam commentedThe change is consistent with those that were made in the related issues. So I think it's fundamentally sound. But I do believe that it needs tests. After all, this is already a regression. You should be able to add an assertion to
Drupal\Tests\system\Functional\Form\ElementTest::that checks to see if the CSS file is loaded into the page's HTML. I'm setting the issue status to Needs Work for this to be done.I also looked into the
.form-compositeclass in this render array. I had to rewind back to D9 to get a decent answer about whether or not this is another class with a regression. I don't think it was part of a system library. Instead, it was provided by Classy. So unlike.fieldgroupit was only styled by themes. I don't believe any changes are necessary for it.Comment #11
mehdi.najeddine commentedAdded a test to ElementTest, as suggested in #9. It loads form-test/radios-checked and checks that fieldgroup.module.css is in the page. The test fails without the fix in CompositeFormElementTrait and passes with it.
Generated with the help of an LLM.