Score:0

How to limit the depth of embedded referenced entities

cn flag

Using Drupal 9 or 10 Using a node type Page with one entity reference field, which is displayed as rendered entity, displaying the same Page content type.

When viewing a page, how do I prevent the page from having endless nested pages in it, leading to infinite loading? I like to limit the nesting to 4 levels deep.

Kevin avatar
in flag
What do you mean endless nested pages? You can set field cardinality to 4. If you are trying to create hierarchy, I suggest using the menu system. Using regular reference fields does not necessarily imply hierarchy at all (outside of Taxonomy or Menu Links, because it has support for that).
cn flag
What I mean is that when a page display includes a fully rendered other page (in its entity reference field) which again has the same entity reference field thus fully rendered third page, that third page also has a fully rendered fourth page etc etc then there is infinite loading of pages. I want to prevent the infinite loading of nested pages from happening, but want to allow e.g. 4 nested pages to be displayed in each other.
sonfd avatar
in flag
My guess is you'll need to create a custom field formatter for you entity reference field.
mx flag
This module might be a good direction for you: [Custom Formatters](https://www.drupal.org/project/custom_formatters)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.