Problem/Motivation

It seems like field groups are not compatible with field layout. The groups I created for a display simply disappeared after enabling field layout. Also, if I try to create any new groups, they simply disappear immediately.

Steps for reproducing

  • Create a field group for a entity display
  • Enable field layouts
  • Save entity display using some field layout
  • Field groups are gone, kaboom!

Proposed resolution

- Change render and nest logic and use the #group functionality

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

marco.falconi’s picture

I'm having the same issue..

nils.destoop’s picture

This will need some work, but i'll investigate it. First commit is coming any moment. This will fix an issue when you change layout.

  • zuuperman committed 5230659 on 8.x-3.x
    Issue #2878359: Field groups are not compatible with field layout. Part...
brayfe’s picture

I am using the 8.x-3.x-dev version of Field_Group and have come across the same issue as the OP. Field Layout version 8.3.2. Enable both Field Layout and Field Group. Edit the structure of a content type. Create a grouping on the "Manage Display" tab of the content type. Choose any layout (2 Column, 3 Column) for the Layout Settings, then move groups into the new layout sections. The groupings don't disappear from the admin form, but are not displayed when viewing the content. The fields are in the correct layout regions, just not grouped or collapsed accordingly.

ricksta’s picture

Confirmed. The same behavior is happening for me, as mentioned above. I've used Field Group for years. It's been a basic part of my site building kit. Thanks to the developers for all the work they've done so far. I'm hoping this get fixed soon for D8.

nils.destoop’s picture

Status: Active » Needs work
FileSize
6.56 KB

WIP patch. basic rendering of forms is fixed with this patch. But I still have to run tests and see what gets broken.

nils.destoop’s picture

Issue summary: View changes
Kris77’s picture

Hi @zuuperman, I applied your patch and now it seems to work.

I use Drupal 8.35 with FIELD_LAYOUT installed and FIELD_GROUP 8.x.3.dev. PHP 7.0

Thank you so much.

bserem’s picture

Patch didn't work for me:

Drupal 8.3.5 (composer template)
Field_group 8.x-3.x-dev (commit:83c00b5) with patch from #7
Field_layout enabled.

I assign a simple field group div which never gets displayed.

nils.destoop’s picture

Status: Needs work » Needs review
FileSize
16.3 KB

New patch. This patch is now for both forms as entity displays (i tested on a node). The unit tests are also green.

nils.destoop’s picture

webcultist’s picture

Just tested. With the #11 patch & without, the groups are not visible when a layout ist chosen. :/

webcultist’s picture

Status: Needs review » Needs work
_dcre_’s picture

#11 works for me. fieldgroups are now rendering correctly.
However this patch caused paragraphs to stop working.
Whenever i try to add a new paragraph item, i get a (silent) ajax error.

drupal logs show the following

Location: http://myurl/node/add/mycontentype?_wrapper_format=drupal_ajax&ajax_form=1
Message: LogicException: Unable to parse the controller name "field_group_form_pre_render". in Drupal\Core\Controller\ControllerResolver->createController() (line 120 of /mypath/core/lib/Drupal/Core/Controller/ControllerResolver.php).

archnode’s picture

Just as a small heads up: Modules that provide field group integration like "profile" will crash if the patch is applied (as the field_group_form_pre_render function won't exist anymore).

bryanmws’s picture

Follow up issue to have paragraphs supporting this patch: https://www.drupal.org/node/2907094

florianmuellerCH’s picture

Priority: Normal » Major

Also tested with Field Group 8.x-1.0-rc6 and Display Suite 8.x-3.1 - I couldn't even apply patch #11. This is kinda a show stopper right now...

niknak’s picture

This patch work fine for me, Thx

nils.destoop’s picture

@ #18 you need to use fieldgroup 8.3 for drupal core 8.3 and higher.
I'll change the patch to re-add field_group_form_pre_render but mark it as deprecated

freelock’s picture

Given that 8.0 - 8.3 are now EOL, and only 8.4 is supported, why do we have an incompatible release tagged as recommended on the module page? Can we get a recommended release of field_group 8.3?

nils.destoop’s picture

because you can not recommend a dev release. I wanted more people to test this patch, as the rendering process is changed completely. Even for users without field layout

stevieb’s picture

I'm geting a lot of the following errors ... while my site uses paragraphs the groups are not in the the my paragraph types

LogicException: Unable to parse the controller name "field_group_form_pre_render". in Drupal\Core\Controller\ControllerResolver->createController() (line 120 of /var/www/html/core/lib/Drupal/Core/Controller/ControllerResolver.php).

Anybody’s picture

I can confirm #15, #23 and that this major problem still exists with field_layouts in 8.4.x

nils.destoop’s picture

FileSize
597 bytes

All people with fatal errors. That is a known issue. See #17, paragraphs needs an update to support the new patch.
Meanwhile an update patch. The fatal error will be gone then, but no groups will be visible untill the paragraphs module is updated.

afi13’s picture

Status: Needs work » Needs review
Alan D.’s picture

Confused about patch #25, it's attempting to add a function that already exists:

http://cgit.drupalcode.org/field_group/tree/field_group.module?h=8.x-3.x

/**
 * Pre render callback for rendering groups.
 * @see field_group_field_attach_form
 * @param $element Form that is being rendered.
 */
function field_group_form_pre_render($element) {
  if (empty($element['#field_group_form_pre_render'])) {
    $element['#field_group_form_pre_render'] = TRUE;
    field_group_build_entity_groups($element, 'form');
  }
  return $element;
}

I've got the groups showing without this patch, but I can not comment regarding the Paragraph issues people were noting.

Alan D.’s picture

Status: Needs review » Needs work
FileSize
23.51 KB

Quick followup

This was my custom FG plugin for 1.x that was rendering fine in 1.x. It shows the first non-empty field assigned to the group and hides the rest.

In 3.x, the element array is not populated with the actual fields (array keys are set with NULL values), so it's impossible to interact with the fields. And the $element array is not being rendered, though it's child elements are.

  public function preRender(&$element, $rendering_object) {
    $content = NULL;
    if (!empty($this->group->children)) {
      foreach ($this->group->children as $field_name) {
        if (isset($element[$field_name])) {
          if (!$content) {
            $content = render($element[$field_name]);
          }
          hide($element[$field_name]);
        }
      }
    }
    if (!$content && $this->getSetting('empty_text')) {
      $content = new FormattableMarkup($this->getSetting('empty_text'), []);
    }
    if ($content) {
      $element[$this->group->group_name . '_content']['#markup'] = $content;
    }
    else {
      $element = [];
    }
  }

So patch in #25 is outdated and I believe there appears to be an major issue in field_group_fields_nest() that can't find the field to populate the element before the pre-render.

To replicate using 8.x-3.0-beta1, add any group when using field layouts and add some fields to it. The group isn't rendered, but the fields are.

So from my limited testing, the field groups in the display admin pages seem ok, but when viewing these displays, the groups aren't being rendered correctly

chOP’s picture

FileSize
16.3 KB
331 bytes

Patch 11 works, but throws a warning notice when used with PHP 7.1

Warning: Parameter 1 to field_group_form_process() expected to be a reference, value given

This amends patch #11 to address the warning notice.

oriol_e9g’s picture

Same problem and seems that #29 works.

Alan D.’s picture

Status: Needs work » Needs review

Switched over to use Field Layouts so no longer able to review the real patch myself again :)

Fernly’s picture

Status: Needs review » Needs work

I can confirm the patch is not working:
The field groups don't disappear but they are rendered outside of the field layout markup.

cameron prince’s picture

Here's a re-roll of #11 and #29 along with a fix for the issue with the field groups rendering incorrectly on the entity edit form.

There is still one obscure problem I'm having trouble resolving. If you enable a field layout on the default display tab and try to add a field group there is an Notice: Undefined index: name in Drupal\field_ui\Element\FieldUiTable::reduceOrder() (line 236 of core/modules/field_ui/src/Element/FieldUiTable.php). error. Dragging and arranging the field group works, but when you save, the field group isn't staying where you place it and the error displays again.

If you "Show row weights" and place the field group using the selectors, it saves and works properly.

DamienMcKenna’s picture

Status: Needs work » Needs review
Anybody’s picture

Status: Needs review » Needs work

Thank you very much for your great work. Sadly it kills our paragraphs when clicking "Edit" on a paragraph:
Unable to parse the controller name "field_group_form_pre_render". in Drupal\Core\Controller\ControllerResolver->createController() (line 120 of core/lib/Drupal/Core/Controller/ControllerResolver.php). Drupal\Core\Controller\ControllerResolver->getControllerFromDefinition('field_group_form_pre_render') (Line: 376)

Any ideas where to start? I'm willing to debug this with you.

EDIT: My mistake! I also had to apply patch "Fix support for field_group module in combination with field_layout module patch (#2907094: Make paragraphs module working with field_group version 3.x with support for the field_layout module)": "https://www.drupal.org/files/issues/2907094_7_field_group_support.patch"

Now IT WORKS!! Hooray! :) Thank you so much!

My last problem / notice is:
Notice: Undefined index: #group_name in field_group_theme_suggestions_alter() (Zeile 89 in /var/www/vhosts/web10.v1750.ncsrv.de/httpdocs/preview/ife-owl.de.preview.webks.de/modules/contrib/field_group/field_group.module). array(57)
When I edit a paragraph.

But I think we can set this "needs review" again. How can we make sure that #2907094: Make paragraphs module working with field_group version 3.x with support for the field_layout module will be included in paragraphs when this patch is RTBC?

cameron prince’s picture

A user ran into a bug with the patch in #33. I neglected to consider cases where a field group wouldn't have a region, i.e. no field layout. Here's an updated patch with a fix.

DamienMcKenna’s picture

Status: Needs work » Needs review
Anybody’s picture

I just tested the patch from #36 manually in our i18n environment and it still works great. RTBC+1 Please review.

askibinski’s picture

Patch applies but there is an issue with fieldsets in combination with a paragraph + inline entity form.
I am using the paragraphs patch in 2907094.

Reproduce:
* create an entity (in my case a custom entity but another node should also do) with some horizontal tabs
* create an inline entity reference in another node to this entity using a paragraph
* edit node and edit inline

form displays used:
- using paragraphs "experimental" form display
- using "Enline entity form - complex" form display

Expected: tabs
Result: all fields shown without field groups

Note: when editing the entity directly tabs do appear, so it seems to be an issue with inline entity form. Not sure if the the patch should also be for inline_entity_form though.

Update, did some debugging: it seems $element['#fieldgroups'] is empty in field_group_build_entity_groups for my inline entity.
However, they are added in field_group_attach_groups() for the entity.

DamienMcKenna’s picture

Issue tags: +undefined

I think some test coverage improvements would greatly help here.

DamienMcKenna’s picture

Issue tags: -undefined +Needs tests
jwilson3’s picture

Status: Needs review » Needs work

Cross post from #2907094-13: Make paragraphs module working with field_group version 3.x with support for the field_layout module here, because this might be a fundamental issue with this patch and not the paragraphs patch:

Tested with patch in comment #36 and #33 with the Paragraphs patch and in both cases, while the error messages are gone, field groups inside the Paragraph type disappear. If I make the paragraph field 'required' and configure the paragraph widget to auto-create the first instance, then the field groups appear outside the paragraph field straight on the main node creation form on /node/add/page.

I should also point out that without either the patch from this issue nor the patch from #2907094 the field groups on the paragraph type works perfectly fine even with Field Layout module enabled, but breaks when you add a field group to the node itself. It seems like there is something fundamentally wrong with node rendering, and I might suggest looking at an alternate solution (if it exists) that doesn't completely get rid of field_group_form_pre_render since that seems to be working for a number of modules already that depend on it (paragraphs, profile).

DamienMcKenna’s picture

Thanks for the extra eyes, jwilson3.

I'm going to again suggest someone work on improving the test coverage, it'd greatly help.

Anybody’s picture

I can confirm the statement from #42. We're having the same results in our manual tests with the patches. Currently with both patches applied the fieldgroups disappear in paragraphs, which is worse than with no patch. I'd like to help but my knowledge about the things behind this issue is by far too low to provide anything than feedback from my manual tests so far.

Anybody’s picture

New information: We now uninstalled field_layout in a project where the field groups were positioned wrong (weight had no effect in commerce product display) but it didn't change anything. The position is still wrong without field_layout.

were using field_group 8.x-1.x-dev without patches there. So perhaps not all problems in this issue are really related to field_layout?
For example this #2942234: Does not work with commerce or other entities without a "content" render array key seems to be the problem in this case.

steveoriol’s picture

Issue still here with D8.5.0... :-(
One solution at the moment is to use the module "Display Suite" instead, but this does not works for the "form display" only for "display"...

jwilson3’s picture

^^ thanks for pointing to #2942234, where there's a comment:

The root of the problem is thet [sic] field group works with 'content' key in render array. [...] I hope there is more elegant solution to edit function field_group_build_entity_groups.

So perhaps (?) there is some collision between content and the painfully annoying content._field_layout.content that gets injected into Twig templates when Field Layout is enabled (using the "one column" default layout). Just a random guess, no time to investigate more deeply at the moment.

nils.destoop’s picture

Status: Needs work » Needs review
FileSize
39.8 KB

An updated patch. Note, I see people all still using outdated patches. The work for this patch lives in a separate branch: https://cgit.drupalcode.org/field_group/log/?h=field-layout-support

First tests on my side indicate that fieldgroups is working again for:
- node edit form without paragraph
- node edit form with fieldgroups in a paragraph
- node view
- node view with fieldgroups in a paragraph
- node view with field layout
- node view with field layout and fieldgroups in the paragraph

Note: The patch of https://www.drupal.org/comment/12472238#comment-12472238 is still needed.

Anybody’s picture

@zuuperman: Thank you so much!! I'll now try patch #48 from here + #7 from https://www.drupal.org/project/paragraphs/issues/2907094
The patch from #48 is against 8.x-3.x-dev correct?

The ALTERNATIVE would be to use branch "field-layout-support" am I right? Or is #48 against that branch?

Status: Needs review » Needs work

The last submitted patch, 48: field_layout_support-2878359-48.patch, failed testing. View results

Anybody’s picture

I can confirm what CI says: The patch can not be applied against 8.x-3.x-dev

nils.destoop’s picture

Status: Needs work » Needs review
FileSize
37.98 KB

Correct. Patch was broken due to some commits on dev yesterday. Included a new diff of the field layout branch.

Status: Needs review » Needs work

The last submitted patch, 52: field_layout_support-2878359-52.patch, failed testing. View results

Anybody’s picture

Patch applies cleanly now. We'll test the result and report back in the next days. Thank you very very very much for your hard work on it!

oriol_e9g’s picture

There is a PHP error here, missing the final ]:

-        '#attributes' => ['class' => ['field-weight']],
+        '#attributes' => ['class' => ['field-weight'],
Anybody’s picture

I can confirm #55, could you create a new patch perhaps, zuuperman?

nils.destoop’s picture

Damn, the last 8.3.x commit was not in field layout branch, leading to the ] issue. Included updated patch

Anybody’s picture

Thank you very very much! I can confirm that the patch (with manually corrected ]) works GREAT! :)

DamienMcKenna’s picture

Just to let the maintainers know - if you create a branch that starts with an issue number it'll automatically show up in that issue's sidebar; see #2679132: Add UI for feature branches for details.

  • zuuperman committed 5230659 on 2878359-field-layout-support
    Issue #2878359: Field groups are not compatible with field layout. Part...
  • zuuperman committed caaf659 on 2878359-field-layout-support
    #2878359: Added support for multilevel entity forms like paragraphs or...
nils.destoop’s picture

Thx for letting me known. I renamed the branch :)

Anybody’s picture

I can finally confirm that the patch from #57 solves all problems and also works perfectly in paragraphs combined with #7 from #2907094: Make paragraphs module working with field_group version 3.x with support for the field_layout module!

So shell we set this issue RTBC? The paragraphs issue should be RTBC'd and commited when the new branch or patch from #75 is being merged + commited in field_group. Perhaps leave a notice over there or contact the paragraphs maintainer before release?

Anybody’s picture

Status: Needs work » Needs review
jhedstrom’s picture

For folks experiencing the php notice

Notice: Undefined index: name in Drupal\field_ui\Element\FieldUiTable::reduceOrder() (line 236 of core/modules/field_ui/src/Element/FieldUiTable.php)

it is actually unrelated to this issue, and more related to old configs that pre-date core's move to specifying region in entity displays. I've opened #2968184: The region part of entity view config isn't set for old installs, which adds an update hook to set this for old configs.

DuaelFr’s picture

Thanks all that worked on that patch before me :)

I needed a way to install this version through composer so I made a new patch that applies on 8.x-3.x including some minor cleanups.
Given the state of the 2878359-field-layout-support branch I strongly suggest that this patch is applied directly on 8.x3.x instead of merging the branches. The attached interdiff show the diff between my patch and the current state of the branch.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

@DuaelFr thank you this makes field layout work!

joelpittet’s picture

Reviewing the code it looks like there is a few coding standard issues but there are some in the module itself so something for a cleanup maybe with phpcbf?

https://www.drupal.org/node/1587138

DuaelFr’s picture

Do you suggest to fix all coding standards or just those in the patch?

joelpittet’s picture

Sorry, I can see how my message can get confused.

Only fix coding standards within the patch but if they are not fixed here, it would be worth running code sniffer shortly before or after the next release(to minimize patch disruptive rerolls in the queue).

Buzzbee’s picture

I successfully use Field Group in a Drupal 7 installation. It works great. However, due to this incompatibility with field layout (which we use for other styling), I cannot get it to work with Drupal 8.5.4. It just simply does not do anything. Not even the group's div name appears in the html source code! We may be able to use the patch but following your last comments, the code of the patch is not clean. Thus we are hesitant to even try it. Is there a roadmap for the next release which includes this patch? Thanks in advance!

DamienMcKenna’s picture

FileSize
38.39 KB

Rerolled.

DamienMcKenna’s picture

This patch includes the one line fix from #2955526: Error: Call to a member function preRender() on null in field_group_field_group_pre_render() because the line endings being incorrect makes it hard to apply patches via composer.

  • zuuperman committed ef9a94f on 8.x-3.x
    Issue #2878359 by zuuperman, DamienMcKenna, DuaelFr, cameronprince, chOP...
nils.destoop’s picture

Status: Needs review » Fixed
Anybody’s picture

@zuuperman, thank you very very much!! This is one of the most important commits in the last month I think :) There will be many happy faces once the stable is released.

nils.destoop’s picture

Strange. Seems my comment wasn't posted. But thx for the reviewing, everything is now committed to dev :)

miro_dietiker’s picture

Awesome! But so much refactoring without a single line of tests updated / added. Thus it's even harder for me to understand the impact.

Status "Fixed" and tag "Needs tests" seems a bit inconsistent. What's the general rule about test coverage in field_group?
We need to know more details to decide about how we integrate Paragraphs.
#2907094: Make paragraphs module working with field_group version 3.x with support for the field_layout module

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

damondt’s picture

This commit appears to have caused this issue.

weseze’s picture

When can we expect this to be in a release?

Besides from paragraphs, paragaphs asymetric translation widgets also suffers: https://www.drupal.org/project/paragraphs_asymmetric_translation_widgets...

No Sssweat’s picture

Tried applying the patch in #72 with composer update (added it to composer.json) with both stable and latest dev, both failed to apply...

When applying the patch via PHPStorm (my IDE), it causes errors in Drupal.

Is it just me? Can someone confirm that this patch still works?

Anybody’s picture

No, this is closed / fixed. The patch has already been committed. You don't need it anymore if you use the dev version.

ocastle’s picture

I'm also seeing the same issue as #81.

Neither 3.0@rc2 or 3.x-dev versions of the module seem compatible with Drupal 8.8.1 field layout module.

Can anyone else confirm field_group is or isn't working with the latest version of field layout?

komejo’s picture

Using field_group 3.0.0-rc2 with Drupal core 8.8.0 and trying to add a field group to a custom entity results in

Fatal error: Cannot redeclare Drupal\field_group\FieldGroupFormatterBase::process() in /web/modules/contrib/field_group/src/FieldGroupFormatterBase.php on line 233

Update: attempt to patch 3.0.0-rc2 caused 'public function process()' to be applied twice, event though the patch showed as failed.

nils.destoop’s picture

The patch will not apply because this code is already committed to dev. The support should now be fixed again in dev, as we fixed #3095570: after update to 3.0-rc2 field groups are not showing (with field_layout module) last week