Overview

We currently have ClientServerConversionTrait (added in #3478565: Add Entity Update controller) that converts client-side data shape into server-side data shape. We should create ServerClientConversionTrait that converts server-side data shape into client-side data shape.

Proposed resolution

Create a ClientServerConversionTrait trait, extract similar BE logic from ApiLayoutController::buildLayout() and ApiConfigControllers::convertComponentTreeItemToLayoutModel() . Add tests, profit.

Comments

f.mazeikis created an issue. See original summary.

wim leers’s picture

Title: ServerClientConversionTrait » ServerClientConversionTrait — or: introduce a ClientSideRepresentation value object?
Component: Page builder » Data model
Assigned: Unassigned » larowlan
Priority: Normal » Critical
Issue summary: View changes
Issue tags: +maintainability, +DX (Developer Experience)
Related issues: +#3478565: Add Entity Update controller

@tedbow added ClientServerConversionTrait in #3478565: Add Entity Update controller.

I know that @larowlan has a clear idea in his head for how we should approach this. (In another issue I commented in the past hour he was talking about a PHP value object to contain the client-side data model — but I can't find it now 😭)

Alternatively, I could imagine ::toClientSideRepresentation(): ClientSide and ::fromClientSideRepresentation(ClientSide $representation) being added to:

  • ComponentTreeItem
  • PageTemplate
  • Pattern

… and for them to share common logic using a trait.

I'm curious what @larowlan thinks 😊

wim leers’s picture

@larowlan: perhaps you think we should close this in favor of #3489772: [PP-1] Add a param converter and DTO for XB data model? :)

wim leers’s picture

Assigned: larowlan » wim leers

While working on #3484678: Improve or remove ComponentSourceInterface::getClientSideInfo(), it became clear that a related challenge appeared there, which relates closely to what I wrote in #2. See https://git.drupalcode.org/issue/experience_builder-3484678/-/tree/34846..., described in #3484678-20: Improve or remove ComponentSourceInterface::getClientSideInfo(), @larowlan 🤓

wim leers’s picture

Assigned: wim leers » larowlan
wim leers’s picture

ClientSideRepresentation landed in #3484678: Simplify ComponentSourceInterface::getClientSideInfo(), introduce ClientSideRepresentation value object, and leverage it, but it's kinda like JSON:API's CacheableNormalization.

It's not doing the much more advanced transformation that this issue is suggesting/implying. But … I'd definitely be interested in seeing it evolve towards that.

Curious to read @larowlan's thoughts!

larowlan’s picture

Looking good Wim, great stuff