By default, the entity_block module has no protection for recursive rendering. This can cause the error when block is added to itself page.

Error log, stack trace:

The website encountered an unexpected error. Please try again later.
Error: Maximum function nesting level of '256' reached, aborting! in Drupal\Component\Plugin\PluginBase->__construct() (line 53 of core/lib/Drupal/Component/Plugin/PluginBase.php).
Drupal\Component\Plugin\PluginBase->__construct(Array, 'entity_field:node:field_paragraphs', Array) (Line: 56)
Drupal\Component\Plugin\ContextAwarePluginBase->__construct(Array, 'entity_field:node:field_paragraphs', Array) (Line: 58)
Drupal\Core\Block\BlockBase->__construct(Array, 'entity_field:node:field_paragraphs', Array) (Line: 113)
Drupal\ctools_block\Plugin\Block\EntityField->__construct(Array, 'entity_field:node:field_paragraphs', Array, Object, Object, Object, Object) (Line: 127)
Drupal\ctools_block\Plugin\Block\EntityField::create(Object, Array, 'entity_field:node:field_paragraphs', Array) (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('entity_field:node:field_paragraphs', Array) (Line: 76)
Drupal\Component\Plugin\PluginManagerBase->createInstance('entity_field:node:field_paragraphs', Array) (Line: 81)
Drupal\Core\Plugin\DefaultLazyPluginCollection->initializePlugin('a48d31d6-0607-489e-8ede-fd353bf7bcdc') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection->get('a48d31d6-0607-489e-8ede-fd353bf7bcdc') (Line: 19)
Drupal\ctools\Plugin\BlockPluginCollection->get('a48d31d6-0607-489e-8ede-fd353bf7bcdc') (Line: 160)
Drupal\Core\Plugin\DefaultLazyPluginCollection->setInstanceConfiguration('a48d31d6-0607-489e-8ede-fd353bf7bcdc', Array) (Line: 135)
Drupal\Core\Plugin\DefaultLazyPluginCollection->setConfiguration(Array) (Line: 153)
Drupal\ctools\Plugin\DisplayVariant\BlockDisplayVariant->setConfiguration(Array) (Line: 470)
Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant->setConfiguration(Array) (Line: 30)
Drupal\Core\Display\VariantBase->__construct(Array, 'panels_variant', Array) (Line: 96)
Drupal\ctools\Plugin\DisplayVariant\BlockDisplayVariant->__construct(Array, 'panels_variant', Array, Object, Object, Object, Object, Object, Object) (Line: 107)
Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant->__construct(Array, 'panels_variant', Array, Object, Object, Object, Object, Object, Object, Object, Object, Object) (Line: 126)
Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant::create(Object, Array, 'panels_variant', Array) (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('panels_variant', Array) (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance('panels_variant', Array) (Line: 87)
Drupal\panels\PanelsDisplayManager->importDisplay(Array, ) (Line: 226)
Drupal\panelizer\Panelizer->getPanelsDisplay(Object, 'default', Object) (Line: 352)
Drupal\panelizer\PanelizerEntityViewBuilder->buildMultiplePanelized(Array, Array, 'default', NULL) (Line: 273)
Drupal\panelizer\PanelizerEntityViewBuilder->view(Object, 'default') (Line: 165)
Drupal\entity_block\Plugin\Block\EntityBlock->build() (Line: 135)

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nikolay.sh created an issue. See original summary.

nikolay.sh’s picture

This patch added the protect from recursive rendering.

nikolay.sh’s picture

Assigned: nikolay.sh » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: entity_block-prevent_recursive_rendering-3160511-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

nikolay.sh’s picture

Added new patch with code style fixes.

nikolay.sh’s picture

Status: Needs work » Needs review
nikolay.sh’s picture

Issue summary: View changes
mglaman’s picture

+1, matches the format of EntityReferenceEntityFormatter. I have one concern over using the entity UUID as the recursive render key. The key should also be based on the entity type.

+++ b/src/Plugin/Block/EntityBlock.php
@@ -159,6 +176,25 @@ class EntityBlock extends BlockBase implements ContainerFactoryPluginInterface {
+        $recursive_render_id = $entity->uuid();
+        if (isset(static::$recursiveRenderDepth[$recursive_render_id])) {
...
+        // Protect recursive rendering.
+        if (static::$recursiveRenderDepth[$recursive_render_id] > static::RECURSIVE_RENDER_LIMIT) {

Drupal does not treat UUID's unique across entity types. Theoretically a Node and Taxonomy Term could have the same UUID without a collision.

mglaman’s picture

Opened an MR with a reroll and a basic output test.

  • mglaman committed 21a7453 on 8.x-1.x
    Issue #3160511 by nikolay.sh, mglaman: Prevent recursive rendering
    
mglaman’s picture

Status: Needs review » Fixed

Thanks, @nikolay.sh! Merged.

Status: Fixed » Closed (fixed)

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