Field Group that is not Empty is Being Hidden

Created on 4 June 2025, about 1 month ago

Problem/Motivation

After updating to v4.0, one of the nested field groups on a node does not display even though it is not empty.

After reviewing the differences between v4.0.0 and v8.x-3.6, I found that the changes in Nested groups render on other entity forms (or when fields are inaccessible) when they shouldn't were the cause.

The code loops through an array that starts with the fields, then groups. For each of them it checks if it's in the group list that was passed. If it is, it checks the $empty_groups_indication array to see if that group is set as an empty element. In order for a group to not be an empty element, one of its children (field or group) needs to have come before it in the list. In the case of nested groups, if a group from the middle of the nest comes first, none of it's children will have set its $empty_groups_indication entry to false. Then, the next part of the code that would set its parent group to false (not empty) does not run field_group.module, line 1063. That parent then is never set to not empty, causing it and its children not to be displayed

Example structure:

Tabs Group 1
--Child Group (Tab)
----Field
--Child Group (Tab) <--- At the end of the process this group considered empty, but it has children with fields
----Tabs Group 2 <--- After all the fields, this group is checked first. It's 2 child groups have not run yet, so it is treated as empty. The next bit of code to set the parent to not empty doesn't run.
------Child Group (Tab)
--------Field
--------Field
------Child Group (Tab)
--------Field
--------Field
--Child Group (Tab)
----Field

The order the field groups are processed in is determined by the array returned by Element::getVisibleChildren($element). Most of the time, it returns the children in an order that works with the process of marking groups as empty. Sometimes it does not.

🐛 Bug report
Status

Active

Version

4.0

Component

Miscellaneous

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @redneko
  • First commit to issue fork.
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱
  • Merge request !114Repeat the steps that are causing the problem → (Open) created by alorenc
  • Pipeline finished with Failed
    16 days ago
    Total: 344s
    #526313
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱

    I was able to replicate the issue consistently.

    I created the following nested group hierarchy:
    - Level 1 (parent of Level 2)
    - Level 2 (parent of Level 3)
    - Level 3 (contains the body field)

    I then reorganized the structure using the Field Group UI:
    - Level 3 becomes the top-level group
    - It contains Level 2
    - Which contains Level 1
    - And Level 1 contains the body field

    I exported the configuration and noticed. The weight values were correctly updated. However, the field order in the YAML config remained unchanged, still reflecting the original nesting order.

    It looks like the Field Group module builds the field group hierarchy based on the order of items in the YAML configuration file, instead of relying solely on the weight and parent_name properties.

    This becomes problematic when reversing the hierarchy (e.g., changing a parent into a child or vice versa), because:
    * The updated structure is not respected during render
    * Fields and groups may not display correctly, even if weight and parent_name appear valid

  • Pipeline finished with Failed
    16 days ago
    Total: 657s
    #526828
  • Pipeline finished with Failed
    16 days ago
    Total: 473s
    #526853
  • Pipeline finished with Failed
    15 days ago
    Total: 443s
    #526976
  • Pipeline finished with Success
    15 days ago
    Total: 807s
    #527016
  • Pipeline finished with Canceled
    15 days ago
    Total: 402s
    #527035
  • Pipeline finished with Success
    15 days ago
    Total: 375s
    #527040
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱

    The function field_group_remove_empty_form_groups expects that groups are ordered from parent to child
    Added an additional function which orders groups.

  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱
  • Thank you for the work alorenc.

    I tested the fix on the site were I found the issue. The missing field group and its children are now displaying, and I did not find any evidence that this fix caused any new issues. I tried making new nodes with different configurations of field groups and found everything to work as expected.

    The coding itself looked good to me, but I am not confident in this area. I will leave this issue in 'Needs review' so someone else can check that, and also corroborate that the fix works.

Production build 0.71.5 2024