2

I would like to know how best to manage a content type having 1:n parent-child relations in Drupal 8.

I need to display a view of the relationships. Although in theory unlimited I anticipate the depth will not exceed 4 generations.

As shown in my diagram below, C is a child of B. D & E are children of C etc:

-instanceA
-instanceB
--instanceC
---instanceD
---instanceE
----instanceF
...

I presume entity reference is the way to go. From my limited D6/7 experience I prefer having a parent ref on a child (having unlimited child inline entity references can seem confusing to my less web savvy users - a single parent from a drop down select is clearer). Although I am happy to be convinced otherwise if other factors outweigh this.

This stack exchange answer suggests the Views Tree module might have worked but it does not seem to be porting to D8.

I think waiting for the Views Field View module to be ported to D8 might provide a solution but this seems overkill.

This is such a basic need I suspect in my lack of experience I am missing a simple solution. Any suggestions how best to approach this appreciated.

1 Answer 1

1

Yes I was missing an obvious answer. As provided by steeph on drupal forum.

Have an entity reference (unlimited) that points at the children. In the content type teaser display include the children field and set that to display the teaser view. You then have a recursive view of all descendants in teaser view mode. Obviously you could create a custom view mode if needed but this is the principle.

Create a view which at the top level only displays views which have no parent (using relationship and filter). Make sure it is set to display content>teaser and you should be seeing a flat list of instances. Use css to add a margin-left to your list-items and job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.