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

Command icon 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

fago created an issue. See original summary.

fago’s picture

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 #3519523: Support component and astro_island render arrays and #3498005: Render a tree of XB components into custom elements
#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.

fago’s picture

Title: Improve mapping render-arrays to custom elements » Introduce an extensible service for converting render-arrays to custom elements

fago’s picture

Status: Active » Needs review

  • fago committed 7e6e2b1c on 3.x
    refactor: #3534177 New, extensible API for converting render-arrays to...
fago’s picture

Status: Needs review » Fixed

code is clean now and comes with tests + works great. This solves converting render-array of canvas_pattern_block module + implements a flexible API for future additions.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.