Problem/Motivation

The EntityReferenceEntityFormatter::RECURSIVE_RENDER_LIMIT constant, by name, would suggest it's some sort of recursive protection but it is not and the constant doxygen accurately describes it:

The number of times this formatter allows rendering the same entity.

We ran into the problem where rendering the same more than 20 times were impossible on the same page. The last time this code was worked on in #2073753: Fix and add tests for the recursive rendering protection of the 'Rendered entity' formatter the code was changed in a way the counter only ever grows and never decreases. The motivation and implementation discussion for the previous version is lost in the mists of time because it was there in the commit adding the whole code to core.

Also, rendering the same entity , or more accurately, the same entity chain biting its own tail 20 times might easily beat the purpose of this codebase which I suspect is avoiding PHP WSODing because the call stack becomes too high. Imagine A->B->C->D->E->A , that'll be a lot of calls before the recursive checker finds A 20 times.

Steps to reproduce

Create a node referring itself, watch it rendered 20 times before Drupal stops. Create 21 node referring the same media, render them on the same page, watch (rather perplexed) as the last one will be empty.

Proposed resolution

Since the function call just before the recursion check makes sure an entity referred by an en entity reference field can find its parent during formatting, just climb the tree and immediately halt if self is found.

Remaining tasks

?

User interface changes

? Previously you could see the same entity (or entity chain) rendering 20 times, now it renders once and stops. But since this triggers an error, would this be something people leave in place?

API changes

It becomes possible to render the same entity more than 20 times.

Data model changes

Release notes snippet

Comments

Charlie ChX Negyesi created an issue. See original summary.

ghost of drupal past’s picture

Title: The entity reference recursive rendering protection is problematic » The entity reference recursive rendering protection is too good
StatusFileSize
new8.19 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3168059_2.patch, failed testing. View results

ghost of drupal past’s picture

Status: Needs work » Needs review
StatusFileSize
new9.69 KB

Checking entity same-ness is hard. Also, there are two of these and the media embed filter simply stops rendering the same entity if it is done more done twenty times. I have for now just patched out the constant and perhaps attack it in another issue?

maacl’s picture

ghost of drupal past’s picture

Status: Needs review » Closed (duplicate)