Code Components as Block Overrides, step 1

Created on 12 February 2025, about 2 months ago

Overview

The first sentence on https://www.drupal.org/project/experience_builder โ†’ starts with:

The Drupal Experience Builder module will 1) enable site builders without Drupal experience to easily theme and build their entire website using only their browser

"entire website" includes blocks, such as menu blocks, breadcrumb block, etc. So what we want is for an in-browser-editable JS code component to be able to take over the entire HTML rendering of a block. That way, a site builder can customize the HTML and CSS for blocks the same way as they can for "regular" code components.

Proposed resolution

The following represents a minimal implementation. Followup issues will be opened to expand on the functionality, such as adding support for variants and other features.

  • Add an override property to the JavaScriptComponent config entity type. The value can either be NULL or the base plugin ID of a block plugin. If it's NULL, the JS component is a regular code component. If it's a block plugin ID, no Component config entity gets made for the JS component: i.e., it's not something that can be dragged onto the page building canvas, instead it's the JS code that will override block.html.twig of the corresponding block.
  • To make the above component override block.html.twig, within BlockComponent::renderComponent(), instead of where we currently set '#theme' => 'block', check to see if a JavaScriptComponent entity exists with an override property equal to the block's base plugin ID. If it does, then set '#theme' => 'block__' . strtr($block->getBaseId(), '-', '_') . '__as_js_component' and also add the JavaScriptComponent entity as another property on the render element. This naming of the theme hook means that all preprocess functions for block__BASE_ID still run.
  • Implement a theme function for the above theme hook that renders an astro_island element with the right props and slots. Create the right props and slots from the theme function arguments based on what makes sense to pass to the JS component. Here we can simplify significantly relative to what Drupal normally passes to Twig templates.
  • In future issues, we'll make the XB UI able to create these override components, but for the scope of this issue, let's add a test module that contains a config entity for a JS component whose override is set to system_menu_block. We can add config entities that override some of the other blocks in a followup.

User interface changes

โœจ Feature request
Status

Active

Version

0.0

Component

Theme builder

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024