Infinite recursion on field_group_field_info_max_weight()/field_group_info_groups()

Created on 8 March 2018, over 6 years ago
Updated 10 June 2023, about 1 year ago

Problem/Motivation

I'm using field_group on one of my content types. Today I needed to add a new base field (boolean) on the same content type, and the field needs to be in the form display. I didn't want to set a weight, as I'm expecting Drupal will add one for me, by calculating the EntityFormDisplay::getHighestWeight().

There is an infinite loop in this logic when Drupal try to rebuild the form display - by visiting the content type Manage form display page with an empty cache - and field_group is part of the process.

I'm raising this a Critical because the Manage form display page becomes unresponsive.

Below the xdebug error stack:
Fatal error: Maximum function nesting level of '2048' reached, aborting!

[...]
19	Drupal\field_layout\Form\FieldLayoutEntityFormDisplayEditForm->getEntityFromRouteMatch( )	.../HtmlEntityFormController.php:73
20	Drupal\field_layout\Form\FieldLayoutEntityFormDisplayEditForm->getEntityDisplay( )	.../EntityDisplayFormBase.php:70
21	entity_get_form_display( )	.../EntityFormDisplayEditForm.php:56
22	Drupal\Core\Entity\Entity::load( )	.../entity.inc:558
23	Drupal\Core\Config\Entity\ConfigEntityStorage->load( )	.../Entity.php:524
24	Drupal\Core\Config\Entity\ConfigEntityStorage->loadMultiple( )	.../EntityStorageBase.php:212
25	Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple( )	.../EntityStorageBase.php:242
26	Drupal\Core\Config\Entity\ConfigEntityStorage->mapFromStorageRecords( )	.../ConfigEntityStorage.php:189
27	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->__construct( )	.../EntityStorageBase.php:322
28	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->__construct( )	.../EntityFormDisplay.php:129
29	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->init( )	.../EntityDisplayBase.php:143
30	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->init( )	.../FieldLayoutEntityDisplayTrait.php:107
31	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->setComponent( )	.../EntityDisplayBase.php:197
32	Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay->getHighestWeight( )	.../EntityDisplayBase.php:365
33	Drupal\Core\Extension\ModuleHandler->invokeAll( )	.../EntityDisplayBase.php:409
34	call_user_func_array:{/var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:402} ( )	.../ModuleHandler.php:402
35	<strong>field_group_field_info_max_weight( )	</strong>.../ModuleHandler.php:402
36	<strong>field_group_info_groups( )	</strong>.../field_group.module:142
37	Drupal\Core\Entity\Entity::load( )
[...]

At this point the loop starts, field_group_info_groups() has called EntityFormDisplay::load() in 37, which is what actually started the process on 21/22.

How to reproduce:

  1. Add field_group to your content type (although by reading the code it looks like having field_group module enable is enough to trigger the bug.)
  2. Add a base field to your content type with setDisplayConfigurable('form', TRUE), w/o specifing a 'weight' in setDisplayOptions()
  3. flush the cache
  4. Visit your content type Manage form display.
  5. You either see the blank page of dead, or any kind of php failure or - with xdebug enabled - "Fatal error: Maximum function nesting level of 'xxx' reached, aborting!"

Proposed resolution

I'm not sure what the solution can be in here. It looks like field_group is doing as expected, and core doesn't give much information from where to pull the weight on EntityFormDisplay::getHighestWeight() other than from the display itself.
But if this is being rebuilt then an infinite loop is created.

Remaining tasks

Figure it out what to do, then fix it.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇹Italy gambry Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany donquixote

    Actually another perhaps "cleaner" solution would be if `field_group_info_groups()` would not load the complete view mode / form mode, but just the raw config data. But I don't know if that is possible or would cause other problems.

  • 🇩🇪Germany donquixote

    Actually the entire mechanism and hook in core are quite problematic and seem to be not very useful.
    The only implementation I could find is from field group.

    And I wonder if it ever does anything useful. I would think that it runs into the infinite recursion.

Production build 0.69.0 2024