Drupal is a registered trademark of Dries Buytaert

entity_deep_token

13 sites Security covered
View on drupal.org

Entity Deep Token

Provides customizable tokens to recursively access fields of related entities.

This module defines a new token type called `entity_deep_token`, which allows you to traverse relationships between entities (such as nodes) and access properties like ID, label, bundle, or raw field values, even across multiple levels of depth.

Purpose

By default, Drupal’s token system only supports direct (one-level) relationships. This module enables token-based access to deeply nested related entities, which is particularly useful for:

  • Hierarchical breadcrumbs generation.
  • Metadata generation based on related entity values.
  • Custom URL building and conditional logic.

Installation

Install the module via Composer:

composer require drupal/entity_deep_token

Enable it via the admin interface or Drush:

drush en entity_deep_token

How to Use

The module adds a new token type: entity_deep_token. It works in any entity context (e.g., node) and allows you to traverse entity reference chains using a structured syntax.

General Syntax

[entity-deep-token:<field>:entity:<field>:entity:<property>]

  • <field>: Name of the entity reference or other field.
  • entity: Indicates traversal to the referenced entity.
  • <property>: Values like id, label, bundle, value, target_id, etc.

Example 1:

degree node → department → school

Entity relationship:

degree → field_department → department → field_school → school

Get the school node ID:

[entity-deep-token:field_department:entity:field_school:entity:id]

Get the school node title:

[entity-deep-token:field_department:entity:field_school:entity:label]

Get the school node bundle:

[entity-deep-token:field_department:entity:field_school:entity:bundle]

Example 2: Get raw creation date from a related entity

Suppose you have an entity reference field field_related_node and you want the creation timestamp:

[entity-deep-token:field_related_node:entity:created:value]

Limitations

Only works when in an entity context (node, user, taxonomy_term, etc.).

Does not yet support multiple values in reference fields (only the first item is accessed).

Does not format raw values (e.g., timestamps are not human-readable).

Future Ideas

  • Support multiple field values (e.g., 0, 1, etc.)
  • Support date formatting via date:format
  • Better integration with the Token UI (autocomplete suggestions)

Maintenance

This module is experimental but stable. Contributions, bug reports, and feature requests are welcome.

Activity

Total releases
5
First release
Jun 2025
Latest release
7 months ago
Release cadence
8 days
Stability
80% stable

Release Timeline

Releases

Version Type Release date
1.0.3 Stable Jul 25, 2025
1.0.2 Stable Jul 24, 2025
1.0.1 Stable Jun 26, 2025
1.0.0 Stable Jun 25, 2025
1.0.x-dev Dev Jun 25, 2025