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:
- 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.)
- Add a base field to your content type with
setDisplayConfigurable('form', TRUE)
, w/o specifing a 'weight' in setDisplayOptions()
- flush the cache
- Visit your content type Manage form display.
- 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.