Problem/Motivation
The Block module provides the block theme hook, its template suggestions, and its default block.html.twig template.
Without the Block module, build() still returns a block plugin's content. Rendering it directly, however, bypasses block.html.twig and any matching block--*.html.twig override, so changes themers make to the wrapper markup in those templates have no effect.
Furthermore, Drupal's UI relies on local task blocks being placed in a theme region. Without the Block module, SimplePageVariant does not display local tasks anywhere at all, which effectively renders various parts of the UI unusable unless you type in the URL.
Now the configuration entities and UI for placing blocks in theme regions do belong in the Block module. That's the module's job. But if a caller doesn't need either of these, it shouldn't need the Block module only to properly honor the active theme's block templates, or to meet basic navigation needs of its own UI.
Layout Builder, for example, manages its own block placements in layout sections. Still, it currently needs the Block module to render those blocks using the active theme's templates and to display the Layout tab on individual nodes.
Goal
This issue aims to make standard block theming available without the Block module. Callers could then use the active theme's block templates to render both
- blocks placed in Layout Builder sections and
- the local tasks block itself.
Once SimplePageVariant also displays local tasks without the Block module, Layout Builder can drop its dependency.
Background
The Block module stores block placements in theme regions as configuration entities and provides the UI for managing them.
#1927608: Remove the tight coupling between Block Plugins and Block Entities allowed callers to supply a block plugin's configuration from their own storage, for example from a layout.
#2315333: Move block plugin code out of block.module made the plugin API available under \Drupal\Core\Block even when the Block module is not installed. The intent was to support modules that manage their own block placements, such as today's Layout Builder. @effulgentsia and @tim.plunkett agreed that, of the three layers discussed, only the ConfigEntityType and the UI for placing blocks in theme regions should remain in the Block module.
This issue was split out of #3003610: [PP-3] Remove block.module dependency from Layout Builder.
It also provides the theme hook needed by #2931040: [PP-1] Provide a shared BlockBuilder for rendering block plugins.
Proposed resolution
- Move the
blocktheme hook, its template suggestions, and the defaultblock.html.twigtemplate to the System module. - Move the existing block preprocessing to
\Drupal\Core\Block\BlockPreprocess::preprocessBlock()and register it as the initial preprocess callback for the hook. - Keep a deprecated template at
@block/block.html.twigthat extends@system/block.html.twig. - Update direct references in Drupal Core to use the new path.
Remaining tasks
Review.
User interface changes
None.
Introduced terminology
None.
API changes
The default block template is now available at @system/block.html.twig.
@block/block.html.twig is deprecated for removal.
Data model changes
None.
Release notes snippet
The block theme hook and its default template are now available without the Block module.
Issue fork drupal-3644069
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
panchoFunctionally we're already there, but our BC layer needs to preserve the original order of theme suggestions:
blocksystemsystemThis can only be solved with an opt-in flag. I'm trying this in
default.services.yml:If more hooks move,
theme.order: d12could opt in for all of them.