Overview

#3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree" will add the remaining pieces for "tree" support, which #3455728: FieldType: Support storing component *trees* instead of *lists* and #3460856: Create validation constraint for ComponentTreeStructure laid the foundations for.

But \Drupal\experience_builder\Controller\SdcController::preview() already has:

    // @todo tree recursion — this only supports a flat list
    // @todo Refactor to use \Drupal\experience_builder\Plugin\DataType\ComponentTreeHydrated.

… because it currently uses custom logic to render these.

(// @todo support CSS + JS was handled in #3462450: Load assets inside preview <iframe> when components are added, we just forgot to delete that.)

Proposed resolution

  • Replace the render array with a call to \Drupal\experience_builder\Plugin\DataType\ComponentTreeHydrated::toRenderable()
  • … but that would lose the wrapping markup that allows the UI to identify each component. So make ::preview() recursively update the render array returned by ComponentTreeHydrated::toRenderable()
  • 🎉 Thanks to #3460856: Create validation constraint for ComponentTreeStructure having landed, this can actually go ahead and update ComponentTreeHydrated to already explicitly supported components-in-slots 🚀

User interface changes

None. The whole point is that everything continues to work exactly the same, but:

  1. with less special snowflake logic in SdcController::preview() — instead reusing the server-side foundations for rendering SDCs ⛄️🔥
  2. a solid portion of what #3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree" would otherwise have to do to get previews of trees of components to render, is already taken care of 👍
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

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes

wim leers’s picture

Assigned: Unassigned » tedbow
Issue summary: View changes
Status: Active » Needs review

@tedbow This should be a big accelerator to your work in #3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree" — this will make your work there be visible in the UI.

IOW: this is the subset of #3446722 that interacts with the client directly, and requires server-side code to be updated for the client to be usable.

Review suggestion: review only ComponentTreeHydratedTest. If that part makes sense to you, IMHO you can blindly approve this, because it'll represent a leap forward with strict test coverage. That would unblock you on #3446722, and is an important step towards finalizing the client's data model and the request/response flow.

wim leers’s picture

Title: Refactor SdcController::preview() to use ComponentTreeHydrated » Refactor SdcController::preview() to use ComponentTreeHydrated, and update it to support nested components
Issue summary: View changes

I just realized that the MR's scope goes a bit further than the originally described/intended scope. Updated issue summary to explain why.

tedbow made their first commit to this issue’s fork.

  • tedbow committed c490a366 on 0.x authored by Wim Leers
    Issue #3463986 by Wim Leers: Refactor SdcController::preview() to use...
tedbow’s picture

Assigned: tedbow » Unassigned
Status: Needs review » Fixed

Thanks @Wim Leers

wim leers’s picture

Status: Fixed » Closed (fixed)

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