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
- Install and enable the Field Group module
- Go to Structure > Content types > [Any content type] > Manage display
- Create a field group and add some fields to it
- Drag a child field from the field group upwards to the "ground level" (content region)
- Observe that the field appears visually at ground level
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3539083-field-ui-parent-child-12.patch | 5.47 KB | grevil |
| #10 | 3539083-field-ui-parent-child-10.patch | 5.4 KB | grevil |
| #8 | 3539083-field-ui-parent-child-8.patch | 4.9 KB | grevil |
| #4 | 3539083-field-ui-parent-child-4.patch | 4.19 KB | grevil |
Issue fork drupal-3539083
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:
- 3539083-field-ui-parent-child
changes, plain diff MR !12882
Comments
Comment #3
grevil commentedDone, 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.
Comment #4
grevil commentedStatic patch for the time being.
Comment #5
smustgrave commentedPossible 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?
Comment #7
grevil commented@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.
Comment #8
grevil commentedCurrent state as static patch.
Comment #9
anybodyYeah really important to get this fixed, so we can get the nasty Field Group issues fixed also...
Comment #10
grevil commentedLatest MR as static patch for the time being.
Comment #11
grevil commentedAs said before, testing this would require to install the field_group issue.
Comment #12
grevil commentedComment #13
smustgrave commentedWill leave it here but seems like large enough change it should have some kind of coverage in core.
Comment #14
grevil commentedUnderstandable.
Comment #15
andyf commentedI 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?
Comment #16
grevil commented@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
Comment #17
smustgrave commentedSaving credit for the work here