diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index 180e2b4ef3..313b023d7c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -52,6 +52,25 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { */ protected $entityDisplayRepository; + /** + * An array of counters for the recursive rendering protection. + * + * Each counter takes into account all the relevant information about the + * field and the referenced entity that is being rendered. + * + * @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter::viewElements() + * + * @var array + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. This is no + * longer used. Instead use the private property $entity->_render_path to + * keep track of the path taken by the renderer and detect recursion by + * counting the number of times the renderer takes the same path. + * + * @see https://www.drupal.org/node/2940605 + */ + protected static $recursiveRenderDepth = []; + /** * Constructs a EntityReferenceEntityFormatter instance. * diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index 313b023d7c..0c1311943f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -166,7 +166,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) { - // Protect from recursive rendering. + // Protect against infinite recursion. $recursive_render_id = $items->getName() . ':' . $entity->id(); if (substr_count($entity->_render_path, $recursive_render_id) > static::RECURSIVE_RENDER_LIMIT) { $this->loggerFactory->get('entity')->error('Recursive rendering detected when rendering entity %entity_type: %entity_id, using the %field_name field on the %parent_entity_type:%parent_bundle %parent_entity_id entity. Aborting rendering.', [