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
Issue fork custom_elements-3534177
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 #2
fagoIt 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.
Comment #3
fagoComment #5
fagoComment #7
fagocode 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.