Problem/Motivation

When nested field groups are configured for a form display, we are seeing empty groups rendered on other entity forms for that bundle such as when using the Scheduled Transitions module.

It seems that all but the lowest level of groups are rendered, e.g if you have Group A > Group B > Field Z, then on the Scheduled Transitions Form (and add form) you'll see Group A rendered but it will be empty. Adding a Group C under Group B will show Group A > Group B (empty).

Proposed resolution

Not quite sure...most likely somewhere in field_group_remove_empty_form_groups

Remaining tasks

Identify bug, write tests, fix it.

Field group configuration

Scheduled transitions display

Command icon 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

acbramley created an issue. See original summary.

acbramley’s picture

acbramley’s picture

This also happens on the Children tab with the Entity hierarchy module

acbramley’s picture

Issue summary: View changes
acbramley’s picture

Issue summary: View changes
acbramley’s picture

Title: Nested groups render on other entity forms » Nested groups render on other entity forms (or when fields are inaccessible) when they shouldn't

This is much easier to reproduce on a simple edit form by nesting 2 field groups, with a single field as a child, then using hook_field_access to deny access to that field. I will work on a test now.

acbramley’s picture

Status: Active » Needs review
StatusFileSize
new2.56 KB

Here's a failing test. I spent quite a bit of time trying to figure it out using the view context but it looks like this bug only exists in the form context.

mnico’s picture

Hello, recently I had to try to find a solution. I upload a patch with the test published by @acbramley to see if it goes well;)

acbramley’s picture

Nice work @mnico! That fixes the issue for me.

tim-diels’s picture

Indeed nice work! This works for me also

dshields’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

acbramley’s picture

StatusFileSize
new3.53 KB

Rerolled against latest dev. Removed the trait changes as we now have similar logic in there.

weekbeforenext’s picture

Patch #12 works for me. Thanks!

rp7’s picture

I was using the patch from #2849279: Make the moderation control form an entity form so that it validates entities before save and field group tabs were appearing on the content moderation form rendered by the content_moderation_info_block module. Patch in #12 fixed this. Thank you!

mandclu’s picture

I've tried the patch in #12, and it doesn't seem to resolve the problem of empty fieldsets being rendered when the fields don't appear because of translation settings, as originally reported in #3200703: Empty fieldgroups are showing in forms (updated)

rp7’s picture

I started to wonder why these field groups are actually rendered at all on forms such as the scheduled transitions add form. It appears the Field Group is doing this based on the active form display: https://git.drupalcode.org/project/field_group/-/blob/8.x-3.x/field_grou... - which sounds logical.

The scheduled transitions add form, however, is a custom (entity) form but it's form state has a form display that is actually incorrect (in my case it has the "default" form display, but that's actually not the one being displayed). Possibly this is something that should/can be fixed in the Scheduled Transitions module (and possibly other modules, such as Content Moderation Info Block as well). I have created a ticket in the Scheduled Transitions module's issue queue with a possible fix: #3264674: Field groups are added to the scheduled transitions add form .

rp7’s picture

StatusFileSize
new3.53 KB

Rerolled against latest dev.

maxilein’s picture

It does not apply any more to the later devs.
e.g. drupal/field_group dev-3.x eb2167b7

nadim hossain’s picture

StatusFileSize
new3.54 KB

Re-rolled the patch 12 against - 8.x-3.6

acbramley’s picture

Patches don't run tests, rolled into an MR.

acbramley’s picture

Fixed CSpell failure, the phpstan failure is on HEAD.

maxilein’s picture

It does apply to fieldgroup 3.6.0.
Thank you

anybody’s picture

Version: 8.x-3.x-dev » 4.x-dev

Thank you for your great work and tests here @acbramley!

  • anybody committed 852d4699 on 4.x authored by acbramley
    Issue #3098550 by acbramley, mnico: Nested groups render on other entity...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.