[PP-1] Support `{type: object, ā€¦}` prop shapes that require *multiple* field types

Created on 13 August 2024, 8 months ago

Overview

So far, XB has only had example SDCs and has hence only supported {type: object, ā€¦} SDC prop shapes that have an equivalent field type. For example:

      "title": "image",
      "type":  "object",
      "required": ["src"],
      "properties": {
        "src": {
          "title": "Image URL",
          "$ref": "json-schema-definitions://experience_builder.module/image-uri"
        },
        "alt": {
          "title": "Alternative text",
          "type": "string"
        },
        "width": {
          "title": "Image width",
          "type": "integer"
        },
        "height": {
          "title": "Image height",
          "type": "integer"
        }
      }

maps perfectly onto the image field type (and can also be perfectly represented by a media reference to an @MediaSource=image-based media type/bundle ā€” see šŸ“Œ Introduce `hook_storable_prop_shape_alter()`, use it to prefer the Media Library widget for "image" PropShape if Media Library is installed Fixed ).

But what about {type: object, ā€¦} shapes that do not happen to have an equivalent in Drupal? How do we map those?

šŸ“Œ Introduce an example set of representative SDC components; transition from "component list" to "component tree" Fixed is introducing the first example SDCs that show that very problem, because it includes for example the following SDC prop JSON schema:

      "title": "Heading",
      "type": "object",
      "required": ["text", "element"],
      "properties": {
        "text": {
          "type": "string",
          "title": "Text",
          "description": "The heading text.",
          "examples": ["A heading element"]
        },
        "style": {
          "type": "string",
          "title": "Style",
          "description": "The heading style to use.",
          "enum": ["primary", "secondary"],
          "examples": ["primary", "secondary"]
        },
        "element": {
          "type": "string",
          "title": "Element",
          "description": "The HTML element to use.",
          "enum": ["div", "h1", "h2", "h3", "h4", "h5", "h6"],
          "examples": ["h1", "h2", "h3", "h4", "h5", "h6", "div"]
        }
      }

Proposed resolution

Options:

  1. StaticPropSource currently can only have a single field type (see \Drupal\experience_builder\PropSource\StaticPropSource::__construct(fieldItem)). As long as that remains the same, the only choice would be to generate a composite field type containing all the necessary field types ā€” basically: https://www.drupal.org/project/field_union ā†’
  2. Introduce a new CompositeStaticPropSource, that contains multiple StaticPropSources ā€” very similar to the current \Drupal\experience_builder\PropSource\AdaptedPropSource
  3. Either of the above is going to result in rather complex (read: lengthy) JSON blobs. Rather than storing a serialized StaticPropSource, for any component prop that does not rely on any computed field property (e.g. the URL of an "image" field type, the processed text of a "text" field type, etc.), store only the resulting value, and "just" compute the appropriate field type on the fly, at edit time, using the infrastructure that šŸ“Œ Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed introduced.

User interface changes

TBD

šŸ“Œ Task
Status

Postponed

Component

Page builder

Created by

šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

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

Comments & Activities

Production build 0.71.5 2024