Problem

We defined some custom entities which's template function do not always use "elements" as render array.

When I add a field group, for example a html element, the fields are not grouped within the configured element in the frontend markup.

Proposed resolution

Do not rely on "elements", read the configuration of the entity.

Workaround

We switched the render array key all back to "elements". That helps for now.

CommentFileSizeAuthor
#4 render-array-key-check-2557877-4.patch682 bytesdanielbeeke

Comments

axe312 created an issue. See original summary.

axe312’s picture

It also looks like 'content' as render variable is also required to be used that field group works. Is this the normal pattern and all entities should use 'elements' & 'content'?

danielbeeke’s picture

We have this same issue while using Display Suite.

Changing the start of the function like this:

function field_group_build_entity_groups(&$vars, $context = 'view') {

  if ($context == 'form') {
    $element = &$vars;
    $nest_vars = NULL;
  }
  else {
    if (isset($vars['elements'])) {
      $element = &$vars['elements'];
    }
    elseif (isset($vars['content'])) {
      $element = &$vars['content'];
    }
  }

Fixed our problem on the front end.

danielbeeke’s picture

StatusFileSize
new682 bytes

Do not rely on "elements", read the configuration of the entity.

That is difficult if we don't change a lot of things. The function itself does not know what entity is used without going through the render array. I mean $vars['content']['#entity_type']. Is it acceptable to just check what render array key is used?

jpamental’s picture

Hey @danielbeeke -

I'm experiencing the same issue with Display Suite and tried your code (looks like starting on line 286 in field_group.module) but it didn't do a thing. Still no wrapping element (trying to wrap with a div). If I disable the DS layout I get the wrapping class, but then lose DS Extras ability to customize the field markup. Am I missing something from your solution?

Any tips would be most welcome, and I'm happy to reroll as a patch and post back if I can get it working!

danielbeeke’s picture

@jpamental

Have you tried using the dev version of display suite? Have you applied the patch? The patch is better than the code above. It is missing a variable.

jpamental’s picture

@danielbeeke

So I tried again with the dev version of DS (Pretty sure that's what I had, but downloaded again anyway), and installed the patch to the file_group module but no difference: if I have 'one column layout' selected I get the 'expert' field formatting options (from DS Extras) but no wrapping div. If I set the custom layout back to 'none', I get the wrapper but no expert layout options for fields.

Any ideas? I'm not quite sure what to try next. It seems like neither 'elements' or 'content' is the right var to target (or at least it's not targeting it in the right way?)

Thanks,

Jason

bceyssens’s picture

Status: Active » Reviewed & tested by the community

Aspilicious and I are working on DS today. We just tested #2604994: Field group compatibility combined with #2611758: Field UI table is broken for nested elements and patch #4, and it seems to work just fine!

jpamental’s picture

@bceyssens @danielbeeke -

I can confirm as well that when you combine all 3 patches (one for DS, one for Field Group and one core) it is indeed working as it should be!

Thanks!

nils.destoop’s picture

Status: Reviewed & tested by the community » Fixed

Thx for researching this. I tested and committed the patch.

Status: Fixed » Closed (fixed)

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

Status: Closed (fixed) » Needs work

The last submitted patch, 4: render-array-key-check-2557877-4.patch, failed testing.

aspilicious’s picture

Status: Needs work » Closed (fixed)