Move clientside assumptions about prop form data shape into a series of prop specific transforms

Created on 14 January 2025, 3 months ago

Overview

In formUtils.ts we have a function getPropsValues that attempts to map prop values from widget shapes to raw values.

This does things like map <input type="text" name="xb_component_props[a62d549f-d8df-45e8-a313-9110c7cd0a8b][heading][0][value]" to a heading prop. But also to handle things like date-time fields that have two inputs.

Proposed resolution

Remove this from input forms and instead create a registry of transforms
This will be a Javascript map object with keys being transform IDs and values being functions that take some input and transform it.
In Drupal implement hook_field_widget_info_alter() and for each widget, add known transforms that we know are needed for that widget.
When we build the component list in ApiComponentsController include an array of transforms for each prop. For SDC we will be able to do this based on the widget configured in the field_widget: key for each prop.
Write corresponding transforms in clientside code and register them.
Devise a way for other modules to add their own transforms. This will likely be a global on the Drupal object like we have for AJAX commands.
In getPropsValues call each transform in turn and return the final value.
Support a similar approach for Block components, which will likely be far simpler because we're not using widgets.
When a prop values cannot be resolved client side (e.g. things like images might need special handling) support a transform that requires server side transformation - πŸ“Œ Support server side massage and validation of component prop form values Active

User interface changes

πŸ“Œ Task
Status

Active

Version

0.0

Component

Data model

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024