Block field formatter allows recursive rendering

Created on 17 May 2022, over 2 years ago
Updated 13 February 2023, over 1 year ago

Problem/Motivation

There can be a case when the block is rendered inside the same block.

For example, we faced it when Block content has himself as a children in the render tree.
Node -> Paragraph -> Block content -> Paragraph -> Block content.

Also Block content can reference on himself

We are able to to create a block inside the same block and block field formatter has to prevent recursive rendering.

Steps to reproduce

  • Install block content module.
  • Create a block_field field in the block_content entity
  • Create block_content entity
  • Update the block_content and set this block in block_field field of the entity
  • Create a block_field field in the node
  • Create a node with test block_content

Actual result: 503 error.

Expected result: Page is shown.

Proposed resolution

Right now core does not restrict referencing to the same entity (see entity_reference field) but field formatter 'entity_reference_entity_view' (see \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter) has recursive rendering protection (limited to 20) for avoiding infinity loop and fatal errors.

Use recursive limitation similar \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter in \Drupal\block_field\Plugin\Field\FieldFormatter\BlockFieldFormatter.

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

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.

Production build 0.71.5 2024