Problem/Motivation

When I enable Field Group, I get the following error on every page:

Notice: Undefined variable: element in field_group_build_entity_groups() (line 299 of modules/contrib/field_group/field_group.module).

field_group_build_entity_groups(Array, 'page', Array) (Line: 293)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 472)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 88)
__TwigTemplate_dbdef2360c80bd63a5c99f87245c438f4d81dc53d6bcf0b0a8ca910d64c51a56->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/layout/html.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 152)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 95)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 116)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 86)
Drupal\purge_queuer_url\StackMiddleware\UrlRegistration->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 31)
Drupal\gc_api\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 637)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Debug the issue and resolve it. :)

Remaining tasks

  1. Write Patch

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidwbarratt created an issue. See original summary.

davidwbarratt’s picture

Issue summary: View changes
ozin’s picture

Hi @davidwbarratt, could you provide more details? I've installed dev version of this module but did not see those errors.
Drupal version: 8.1.1
Module version: 8.x-1.x-dev

ahebrank’s picture

It's possible for $element to be returned here before it's initialized in field_group_build_entity_groups() if none of the conditionals are met:

  // No groups on the entity.
  if (empty($element['#fieldgroups'])) {
    return $element;
  }

I added

  $element = [];

at the top of the function to mitigate the PHP error, but haven't investigated what this might break.

EDIT: I'm getting this in the stable version--haven't tried dev but the code in vcs looks like it's the same.

achton’s picture

I ran into this problem as well.

We have entity templates enabled for block_content, and when they pass through field_group_build_entity_groups(), they have no 'elements' and no 'content', thus the return statement fails.

  • zuuperman committed b86960f on 8.x-1.x authored by achton
    Issue #2730089 by achton: Notice: Undefined variable: element in...
nils.destoop’s picture

Status: Active » Fixed

Thx for the patch. I committed it to dev.

Status: Fixed » Closed (fixed)

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