Drupal is a registered trademark of Dries Buytaert
cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)! drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! linkit 7.0.15 Minor update available for module linkit (7.0.15). views_data_export 8.x-1.10 Minor update available for module views_data_export (8.x-1.10).

The Entity Build Context module provides a lightweight runtime context stack that tracks entities as they are being rendered.

In complex Drupal architectures—especially those relying heavily on nested entities like Paragraphs, Layout Builder, Blocks, or Media—it can be difficult for a deeply nested child entity or custom field formatter to know what its parent container is. This module solves that problem by tracking the current entity view context and exposing it via a central service.

How It Works

For bundles where Entity Build Context is enabled, the module tracks the rendering lifecycle. Each item in the context stack captures:

  • The active Entity object
  • The Entity View Display (config entity)
  • The active View Mode (e.g., 'default', 'teaser')
  • The Render Build Array

The entity_build_context_manager service allows your custom code to read this data at any point during the render cycle, ensuring safe application of cacheability metadata.

Typical Use Cases

  • Parent-Aware Formatting: Access the parent node's data from inside a nested Paragraph or Media item custom field formatter.
  • Inherited Cacheability: Automatically inherit and bubble up cache tags/contexts from a parent entity to nested render arrays.
  • Dynamic Components: Build decoupled or component-driven layouts that need to adapt based on the context of the page or host entity they are rendered within.
  • Debugging: Easily inspect complex, deeply nested entity rendering behavior.

Configuration

  1. Install and enable the Entity Build Context module.
  2. Navigate to the configuration page of any supported bundle (e.g., Structure > Content types > Manage [Type]).
  3. Check the box for Enable entity build context.
  4. Save the bundle.

Developer Usage

The Service

The module provides the entity_build_context_manager service to interact with the runtime stack.

Example: Fetching Context in a Custom Formatter or Preprocess

// Retrieve the service.
$context_manager = \Drupal::service('entity_build_context_manager');

// Get the immediate parent entity context.
if ($parent_context = $context_manager->getParentContext()) {
  $parent_entity = $parent_context->getEntity();
  $view_mode = $parent_context->getViewMode();
  
  // Do something custom based on the parent context...

  // Safely apply cache metadata from the entire build stack to a build array.
  $context_manager->applyCacheMetadata($my_custom_render_array);
}

Technical Specifications & Requirements

  • Drupal Compatibility: Drupal 10.3+ or Drupal 11+
  • Dependencies: None (Zero contrib dependencies)

Activity

Total releases
1
First release
May 2026
Latest release
12 hours ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
1.0.0-beta1 Pre-release May 26, 2026