The Entity Reference (with) Hierarchy module extends Drupal core's standard entity reference field, transforming it from a flat, linear list into a powerful rooted tree structure.

While Drupal core only supports simple lists of references, this module allows you to define complex hierarchies directly within a single field on the host entity.

Architecture: The Rooted Tree Approach

Unlike other hierarchy solutions that create "nested sets" by chaining reference fields across multiple individual entities, this module manages the entire hierarchy map via a single field. This rooted tree architecture stores depth and weight metadata alongside the target ID on the primary entity.

This approach is exceptionally well-suited for Paragraphs, where you may need to manage deeply nested layouts and components without the overhead of cross-entity field chaining.

Key Features

  • Visual Hierarchy Management: Includes a drag-and-drop interface identical to the familiar UI used for managing taxonomy terms or menu links in Drupal core.
  • Single-Field Data Model: The entire tree is stored and managed on the root host entity.
  • Revision Support: Fully compatible with Entity Reference Revisions, allowing for historical tracking and revisioning of the entire hierarchical structure.
  • Ecosystem Ready: Works seamlessly with Inline Entity Form and Paragraphs for advanced content modeling.

Example Structure

The module tracks both delta (weight) and depth to maintain the tree:

  • Reference A (delta 0, depth 0)
    • Reference B (delta 1, depth 1)
    • Reference C (delta 2, depth 1)
      • Reference D (delta 5, depth 2)
  • Reference E (delta 3, depth 0)

Comparison to Entity Hierarchy

It is important to distinguish this module from Entity Hierarchy:

  • Entity Hierarchy creates trees through a chain of reference fields pointing to one another (a nested set model).
  • Entity Reference (with) Hierarchy uses a single field on the primary entity to manage the structure (a rooted tree).

Background & Credits

This project was born from a desire to create a more generic, unstyled version of Bricks. During development, it incorporated improvements and logic inspired by the entity_reference_hierarchy repository by maijs.

Supporting organizations: 
Maintainer

Project information

Releases