Entity Reference Hierarchy
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Overview
Entity hierarchy extends the standard Entity Reference field to store a nested set representation of the the hierarchy.
This allows for efficient querying of the hierarchy.
Features
Integrates with views
Render a list of children at any depth using views
Requirements
- The
previousnext/nested-setcomposer library. - The dbal module.
Known problems
Please use the issue queue to report issues.
If you find your tree is out of whack, rebuild the whole thing if needed using drush entity-hierarchy-rebuild-tree field_parents node where field_parents is the field name and node is the entity type the field lives on. Given the tree is only a representation of the hierarchy, and the canonical source is the entity field values, this rebuilds the tree representation without touching the original values.
Future Improvements
A planned improvement is a formatter that allows children to display a parent or grandparent, of arbitrary depth.
An extremely simple example of this sort of inheritance would be a section title and banner. You may have a website that uses the same section title/banner across several pages, so it would be desirable in this instance to only need to edit the information in one place (e.g. the great great grandparent).
Installation
First install the library:
composer require "previousnext/nested-set"
Determine what entity type you want to have in your hierarchy. Visit the child bundle and add a new field of type Entity reference hierarchy. This will form the reference to the parent. Configure this as a single value field and give it the ability to reference the bundles that can be its parent. Repeat this for any other content-types that can live in the hierarchy.
Create some content and nominate the parent as appropriate.
Create a view and use the 'is child of' argument to filter down to the appropriate children and depth.
