Problem/Motivation

For some reason $destination_bundle_field_names variable is not here at all, so, none of field groups will be copied when cloning display.

Steps to reproduce

1. Add field group to form display on one bundle
2. Try cloning that display to another bundle
3. Field group will not be copied

Proposed resolution

This is simply code mistake, so I will attach patch

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

CommentFileSizeAuthor
#3 field-group-3324488-3.patch546 bytesholo96
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

DavorHorvacki created an issue. See original summary.

holo96’s picture

Issue summary: View changes
holo96’s picture

StatusFileSize
new546 bytes
holo96’s picture

Status: Active » Needs review
anybody’s picture

I can confirm indeed the variable is never defined!

So it will always be unset here without the fix:

if (!isset($destination_bundle_field_names[$child_field])) {
  unset($group_settings['children'][$index]);
}

Where I'm not sure is, if the $destination_bundle_field_names = $destination_display->getComponents(); should be inside the field_groups condition?

So I guess a maintainer will be able to answer this quickly and fix the clear bug. I won't set this RTBC, because I'm not deep enough into this here.

anybody’s picture

Assigned: holo96 » Unassigned
Priority: Normal » Major

Setting priority to major as this is a clear code bug which breaks expected (and existing) functionality (and seems easy to solve, once a maintainer has a short look).

Don't kill me ;) ;)

anybody’s picture

joachim’s picture

Status: Needs review » Needs work
+++ b/src/DisplayCloner.php
@@ -113,6 +113,8 @@ class DisplayCloner {
+    $destination_bundle_field_names = $destination_display->getComponents();

getComponents() does not return field names!

holo96’s picture

@joachim Is naming only issue you have with this?

That's how it is named in module currently only variable init is missing, I guess it went missing in some point

I will create new patch..

anybody’s picture

Just ran into this again, so I'll try to place this on our agenda.

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

grevil’s picture

I can confirm that the patch fixes the issue! Very weird, that the variable declaration of

$destination_bundle_field_names

was somehow removed.

grevil’s picture

Status: Needs work » Needs review

I applied @holo96's patch as an MR changed the point of initialization and renamed the variable, please review!

EDIT: Just saw, that a couple of auto formatting changes were committed as well, hope that's fine.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @Grevil, that's indeed a crazy reason for the bug ;D

I think the fixes are okay, as it's not too many. RTBC! Would be great to have this fixed and Field groups support back again!

mattlc’s picture

Status: Reviewed & tested by the community » Needs work

Hello, thanks for the work.
One missing thing. The code is not taking care of nested field groups.
As far as this is a 1 Year + RTBC issue, I think I can propose this :

         foreach ($group_settings['children'] as $index => $child_field) {
-          if (!isset($destination_bundle_field_names[$child_field])) {
+          if (!isset($field_group_settings[$child_field]) && !isset($destination_display_components[$child_field])) {
             unset($group_settings['children'][$index]);
           }
         }

I can update the branch if modification is OK for you.

I also would like to suggest the ability to choose whether or not the user wants to copy empty groups.

grevil’s picture

@mattlc, feel free to modify the MR!