Cannot add Group to another Group on creation

Created on 28 November 2024, 20 days ago

Problem/Motivation

I have two group types and configured them so one can be added as content to the other using a GroupContentEnabler plugin. Simply being a parent group > sub group concept.

When creating nodes using the entitygroupfield, I can easily add the entity directly to a group when first creating the node when the entitygroupfield's been added in the display configuration. However, when creating a group, it cannot be added directly to another group because the GroupController::addForm() method sets a form state storage value for group_wizard_id. When the entitygroupfield widget is being constructed, the EntityGroupFieldWidgetBase::formMultipleElements() method checks if a group_wizard_id value is set in the form state storage and if so, just returns immediately.

I was wondering what the purpose of this is?

Commenting the lines

if ($form_state->get('group_wizard_id')) {
  return [];
}

out of the top of the formMultipleElements() method doesn't seem to break anything and allows a Group entity to be added to another Group entity on creation.

Steps to reproduce

  1. Create two group types, for a parent and a child group.
  2. Create a node type.
  3. In the parent group, allow the new node type and the child group type to be added as content of the parent group (allowing a group to be added to another group requires a GroupContentEnabler plugin).
  4. In the node's form display set up, add the entitygroupfield (Groups) field to the enabled fields. Do the same for the child group's form display.
  5. Create a standard parent group entity to test with.
  6. Create a new node entity from the node type above and see that the Groups field is included.
  7. Create a new child group entity and check that the Groups field is not there on the form.
  8. Edit the child group entity, check that the field appears.

Proposed resolution

Removed the first 3 lines of EntityGroupFieldWidgetBase::formMultipleElements()

🐛 Bug report
Status

Active

Version

2.0

Component

Widgets

Created by

🇬🇧United Kingdom AlbionBrown

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

Comments & Activities

Production build 0.71.5 2024