Improve mapping render-arrays to custom elements

Created on 4 July 2025, 3 days ago

Motivation

Atm we have a few hard-coded ways to convert Drupal render-arrays to custom elements. We want to extend this by a solution for mapping XB-render-arrays to custom element trees. Before doing so we should introduce one unique way of mapping render-arrays as a central API, that is extensible to further render-elements.

Currently support cases are:

A) Mapping #theme => custom_element as returned by \Drupal\custom_elements\CustomElement::toRenderArray
B) Wrapping un-support render-arrays in a drupal-markup element - this is the fallback.
C) Similar logic, for blocks: \Drupal\custom_elements\CustomElementsBlockRenderHelperTrait::getElementsFromBlockContentRenderArray()
D) Mapping layout-regions of layout-builder in \Drupal\custom_elements\CustomElementGenerator::buildLayoutBuilderContent()

We already have CustomElement::createFromRenderArray() as API to trigger the conversion, it only handles A) and B) atm though.

Proposed resolution

todo

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇦🇹Austria fago Vienna

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

Comments & Activities

  • Issue created by @fago
  • 🇦🇹Austria fago Vienna

    It seems would could do something like the following:

    Allow conversion plugins to be registered. Identify the conversion plugin to use by #type or #theme key.

    Examples of #type and #theme we'll need to implement
    #type component --> logic for XB, see 📌 Support component and astro_island render arrays Active and 📌 Support for Experience Builder Active
    #theme custom_element --> straight conversion from custom element object
    #theme block --> possibly special handling for blocks

    Layouts use varying #theme keys based upon the layout, but have a #layout key. So we might want to support differentiating based upon that also.

Production build 0.71.5 2024