Manage_display_0

The Left and Middle divs do not show up when the entity is viewed in this display mode.
When I change the field widget from "Link" to "Html Element", they are rendered correctly.

Comments

Algeron created an issue. See original summary.

Algeron’s picture

Status: Active » Needs work
StatusFileSize
new41.05 KB

It seems to be related to this code snippet in/src/Plugin/field_group/FieldGroupFormatter/Link.php:

      // Add each child element into the link title, and hide it from being
      // rendered outside of the link.
      foreach (Element::children($element) as $group_child) {
        $element['#title'][] = $element[$group_child];
        hide($element[$group_child]);
      }

A workaround is to add an additional fieldgroup right below the Link fieldgroup:
Manage_display_2
This makes child fieldgroups render correctly inside a Link fieldgroup.

leon kessler’s picture

Hmmm this is quite a tricky one.

It actually makes sense that nested field groups are not rendered, as we're just passing everything into the Link class #title attribute (which I guess does not know how to render field groups).
But what's weird is that double nested field groups do work. Why that is I do not know.

I tried removing the hide() to see if that made a difference, still no joy.

I also tried adding in my own dummy field group, like this:

      foreach (Element::children($element) as $group_child) {
        $element['#title']['field_group_link'][] = $element[$group_child];
        hide($element[$group_child]);
      }

Again, no joy.

If I can work how it's able to render these double nested field groups then I think it will be an easy fix.

henrijs.seso’s picture

[deleted, wrong version]

leon kessler’s picture

Status: Needs work » Needs review
StatusFileSize
new678 bytes

Okay think I've finally found a fix. And it's a pretty simple one.

Incidentally I discovered another issue with nested field groups whereby they are not hidden. I created a separate issue for this: #2827745: Nested field groups are not hidden

I'm marking this as needs review while I do some more testing and ensure both tickets can be closed.

leon kessler’s picture

Status: Needs review » Needs work

Assigning the group by reference doesn't quite work, because
hide($element[$group_child]);
will now hide the field group inside the link as well.

Either need a way to only hide the field group outside of the link (this might need some kind of alter hook). Or actually work out the outer most field group doesn't get it's settings properly assigned.

leon kessler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.99 KB

Okay I think the best solution is to create our own Render Element, that extends the standard Link one. Then we can remove the children, at which point they've already been generated inside the $element['#title'].

Pretty confident with this solution, but will leave this for review will I check further. Also need to start looking at adding some unit tests.

leon kessler’s picture

StatusFileSize
new2.05 KB

Better docblock commenting on class.

  • Leon Kessler committed 22fc497 on 8.x-1.x
    Issue #2774599 by Leon Kessler, Algeron: Other fieldgroups inside Link...
  • Leon Kessler committed 4949aed on 8.x-1.x
    Issue #2774599 by Leon Kessler, Algeron: Better commenting.
    
leon kessler’s picture

Status: Needs review » Fixed

Pushed to 8.x-1.x, and created 8.x-1.0-rc1 release.

Status: Fixed » Closed (fixed)

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