Problem/Motivation

When using the Field UI Manage Display interface with the contrib Field Group module enabled, moving child fields from their parent groups to the "ground level" (content region) via drag-and-drop does not properly update the parent-child relationship. The field appears visually at the ground level, but programmatically still retains its disabled group as its parent.

The root cause is that Drupal core's field_ui.js only handles region changes through the regionChange() method, but lacks equivalent logic for parent changes. When a field is dragged to a different parent or to ground level, the onChange() and onDrop() methods only check for region changes but ignore parent relationship updates.

So why not a dedicated field_group issue?

The field group module is very special, as some core functionalities only exist, to make the field_group even possible. One of these things is the existence of the "parent" select in the "Manage form / view display" and the general logic of a "parent" on form / view display.
There is even an issue on trying to delete this functionality, see #2699907: Parent setting on Form display cannot be changed for custom Content type. That's why I think this functionality should also be merged into core (or even the whole "field_group" module should be part of core through #501366: Add field grouping to Drupal core).

Steps to reproduce

  1. Install and enable the Field Group module
  2. Go to Structure > Content types > [Any content type] > Manage display
  3. Create a field group and add some fields to it
  4. Drag a child field from the field group upwards to the "ground level" (content region)
  5. Observe that the field appears visually at ground level
  6. Check the form data or save and reload - the field still has the group as its parent

Proposed resolution

Add parent change detection and handling to the field_ui.js file.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3539083

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

grevil created an issue. See original summary.

grevil’s picture

Assigned: grevil » Unassigned
Status: Active » Needs review
Issue tags: +Needs discussion

Done, this fixes the issue. Unsure on how to continue here. As said in the issue summary, field_group is very special and there is already code for it in core, might be time to reactivate #501366: Add field grouping to Drupal core, and get the whole thing in core finally.

grevil’s picture

StatusFileSize
new4.19 KB

Static patch for the time being.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Possible to get a test case showing this as an issue? Is it possible without field_groups/should field groups be the one to fix it?

anybody made their first commit to this issue’s fork.

grevil’s picture

@smustgrave unfortunately this isn't possible to reproduce without field_group.

Not quite sure how to fix it in field_group itself, though. I doubt, we should overwrite field_ui.js in field_group.

grevil’s picture

StatusFileSize
new4.9 KB

Current state as static patch.

anybody’s picture

Title: Field UI: Parent-child relationships not properly updated when fields are moved via drag-and-drop » Field UI: Parent-child relationships not properly updated when fields are moved via drag-and-drop (Field Group)

Yeah really important to get this fixed, so we can get the nasty Field Group issues fixed also...

grevil’s picture

StatusFileSize
new5.4 KB

Latest MR as static patch for the time being.

grevil’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

As said before, testing this would require to install the field_group issue.

grevil’s picture

StatusFileSize
new5.47 KB
smustgrave’s picture

Will leave it here but seems like large enough change it should have some kind of coverage in core.

grevil’s picture

Understandable.

andyf’s picture

Possible to get a test case showing this as an issue? Is it possible without field_groups/should field groups be the one to fix it?

I just recreated the issue on 11.x and it seems to be fixed by the PR from #3089151: TableDrag JS :first-of-type issues (which includes tests).

Also updating the repro instructions: as far as I can tell you need to drag the item up for it to fail.

Should this be marked duplicate?

grevil’s picture

Status: Needs review » Closed (duplicate)
Issue tags: -Needs discussion

@andyf you are correct, I am using gin and tried to apply the core changes in their override file before, but it didn't fix the issue for me.

Somehow it does now... I guess I forgot to clear my cache, which is QUITE annoying. Thanks for the heads-up.

Here is the issue on gin's side to fix it in their tabledrag.js override: #3542075: TableDrag JS :first-of-type issues

smustgrave’s picture

Saving credit for the work here