Problem/Motivation
\Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFieldFormatter::viewElements()
tracks how many times an "instance" of a reference has been rendered, to avoid ending up in a recursive loop, which is understandable.
By one "instance" is meant one combination of "Entity with id X of type Y referenced by parent Z of type A in field B".
The problem is that there's no way to reset the counters in (EntityReferenceFieldFormatter::$recursiveRenderDepth
) when you intentionally want to render a node multiple times, possibly as different users would see it.
Most of the time this is papered over by the render cache but in multiple scenarios that won't be hit. The easiest reproduction is via a POST request as POST requests switch off render cache and AJAX requests are always POST (for example see #2500313: Add views render caching on views ajax requests ).
Proposed resolution
Actually keep track of the rendered entities and only stop if there is a real recursion.
Remaining tasks
Come up with an resolution.Agreement on resolution.Write patch/MR- Review
- Commit
- Rejoice!
User interface changes
API changes
A new _render_path
property joins _referringItem
on entities when rendered by the entity reference formatter.
Data model changes
None.