Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Block plugin view builder

Security covered Under active development 185 sites

This module allows developers to render block plugins directly without relying on block content entities. It ensures blocks are properly cached, considering metadata and contexts, which improves the effectiveness of page caching. This functionality is useful for programmatically displaying custom block logic.

Summary

The Block plugin view builder module allows developers to programmatically render (view) block plugins without the need for the wrapping BlockContent entity. This module is an adaptation of the core BlockViewBuilder and makes sure that:

  • Each block gets a cache key, so it can be cached in the render cache
  • Cacheable metadata (including access metadata) is taken into account
  • Block plugins get a lazybuilder callback so they can be correctly placeholdered
  • Context-aware block plugins are supported by passing explicit contexts

This all results in better leveraging of the (dynamic) page cache.

Note: This module does not aim to implement rendering or viewing of BlockContent blocks as these should best be viewed using the core BlockViewBuilder.

How to use

Basic usage:

$blockPluginViewBuilder = \Drupal::service('block_plugin.view_builder');
// Pass optional configuration.
$configuration = [];
$build = $blockPluginViewBuilder->view('plugin_id', $configuration);

With contexts (for context-aware block plugins):

use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\EntityContextDefinition;

$blockPluginViewBuilder = \Drupal::service('block_plugin.view_builder');
$build = $blockPluginViewBuilder->view('plugin_id', [], [
    'node' => new Context(new EntityContextDefinition('entity:node'), $node),
]);

Supported context types:

  • Entity contexts (entity:node, entity:user, etc.) — stored as entity type + ID and reloaded safely in the lazy builder.
  • Scalar contexts (string, integer, etc.) — passed through as-is via JSON.

Requirements

  • PHP 8.1+
  • Drupal 10 or 11

Roadmap

  • Notify other contributed modules that are rendering block plugins of the existence of this project (eg. Block field, Twig tweak, Panels, ...)
Drupal 10–11

Ask your assistant about Block plugin view builder

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

1 tracked project depends on this one

Activity

Tracked releases
5
Tracked since
Mar 2023
Latest release
6 months ago
Releases (12 mo)
1
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.0.6 Stable 10–11 Apr 13, 2026
1.0.5 Stable 8–11 Feb 13, 2025
1.0.4 Stable 8–11 Sep 13, 2024
1.0.3 Stable 8–10 May 28, 2024
1.0.2 Stable 8–10 Mar 13, 2023