Introduce `hook_storable_prop_shape_alter()`, use it to prefer the Media Library widget for "image" PropShape if Media Library is installed

Created on 19 July 2024, 3 months ago
Updated 16 August 2024, 2 months ago

Overview

In order to enable 📌 Media Library integration (includes introducing a new main content renderer/`_wrapper_format`) Fixed before we have 📌 Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed , we could hard code the image (json-schema-definitions://experience_builder.module/image) props to use the media widget temporarily.

Proposed resolution

  1. new configuration to allow declaring a preference for image vs media (which oddly would not be possible through a new experience_builder.settings.yml config, only through a new config entity, because simple config cannot have module nor config dependencies)
  2. updating \Drupal\experience_builder\SdcPropJsonSchemaType::findFieldTypeStorage() to respect that configuration

#3461499-18: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings

… but there was also:
@todo Support a `hook_storable_prop_shape_alter()`, which does NOT allow modifying the schema, but does allow modifying the field type, widget and storage settings. There is a risk here wrt deps, but the fact that after https://www.drupal.org/project/experience_builder/issues/3463999, dependency checking will be handled by config dependencies for us. 👍

… implementing means we solve the original intent, but without any hardcoding 👍 — the act of installing the optional Media Library module would change the default.

That means this will also help with testing 📌 [PP-2] Add ComponentAuditabilityTest Active 👍

Changes

  1. New: hook_storage_prop_shape_alter(), with explicit test coverage (HookStoragePropAlterTest) and API docs
  2. New: CandidateStorablePropShape, the mutable variant of StorablePropShape, used only for that alter hook. Has convenience to/from methods.
  3. New: media_library_storage_prop_shape_alter(), implemented by XB on behalf of Media Library, with explicit test coverage (MediaLibraryHookStoragePropAlterTest)
  4. Improved: StaticPropSource::randomizeValue() now has special handling for entity references, for reasons documented in detail
  5. 🐛 Changed: previously, all logic assumed using the default widget for a field type was fine. This has served XB well so far, but it falls apart for the Media Library use case: that uses the standard EntityReferenceItem field type, configures it to allow only media entities, but Drupal's field system is not smart enough to have storage settings-dependent default widgets. So we need to update StaticPropSource's 3 widget-related methods to require a Field Widget plugin ID to be passed in: changes + updated tests — this part could be split off to a separate issue.
  6. 👆 that was the blocker to write logic to automatically use the widget defined in media_library_storage_prop_shape_alter() — this superficially touches upon something @lauriii and I already identified earlier, but won't affect us in the short term: 📌 [later phase] [PP-1] When the field type for a PropShape changes, the Content Creator must be able to upgrade Postponed
  7. ✅ … this means two crucial @todos added by 📌 Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed are now resolved

User interface changes

📌 Task
Status

Fixed

Component

Page builder

Created by

🇫🇮Finland lauriii Finland

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