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
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3168059_4.patch | 9.69 KB | ghost of drupal past |
Comments
Comment #2
ghost of drupal pastComment #4
ghost of drupal pastChecking 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?
Comment #5
maacl commentedPossibly duplicate of #2940605: Can only intentionally re-render an entity with references 20 times?
Comment #6
ghost of drupal past