Hiding empty field groups in form display is not working

Created on 28 February 2022, over 2 years ago
Updated 8 September 2024, 2 months ago

Problem/Motivation

After upgrading from 8.x-1.x to 8.x-3.x empty field groups are now displaying.

Steps to reproduce

  1. Set up form display to have tabs
  2. Create a tab and give it a field group label and a description
  3. Make sure 'Display element also when empty' is unchecked.
  4. Put a fieldset in the tab
  5. Put a field in the fieldset
  6. Install the field_permissions β†’ module.
  7. Edit the field that you put in the tab and change the field visibility and permissions to 'Custom'.
  8. Change all permissions on the field to have the checkboxes checked for the administrator.
  9. Login as a non-admin who has permission to use the form and visit it

Expected results:
Since the field isn't shown, this tab group is empty, therefore it should be hidden (this was the behaviour in 8.x-1.x).

Actual results:
The tab is shown and has nothing in it.

Cause

This bug was introduced in #2994053: Field Group not working on node edit inside paragraph (Version 8.3) β†’ , specifically this commit: https://git.drupalcode.org/project/field_group/-/commit/ef9a94f222f33ff4...

The previous behaviour was to call field_group_remove_empty_form_groups() if the child is a group, and then the group will have its children checked and if there aren't any, its access will be set to FALSE.

The new code doesn't do this, which means the only check is this:

$empty_element = !(isset($element[$childname]['#type']) || isset($element[$childname]['#markup']) || in_array($exception, $exceptions));

So if the child element has a '#type' then it will be considered not empty. This is always true. A tab has a type of 'details' so it can never be empty. As such, the tab will always be shown regardless of whether there is anything in it.

Proposed resolution

Shouldn't this code have some kind of check to see whether the tab has visible children in it?

πŸ› Bug report
Status

Needs review

Version

4.0

Component

Miscellaneous

Created by

πŸ‡¬πŸ‡§United Kingdom Rob230

Live updates comments and jobs are added and updated live.
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.71.5 2024