Overview
In order to enable #3454173: Media Library integration (includes introducing a new main content renderer/`_wrapper_format`) before we have #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings, we could hard code the image (json-schema-definitions://experience_builder.module/image) props to use the media widget temporarily.
Proposed resolution
- new configuration to allow declaring a preference for
imagevsmedia(which oddly would not be possible through a newexperience_builder.settings.ymlconfig, only through a new config entity, because simple config cannot have module nor config dependencies)- updating
\Drupal\experience_builder\SdcPropJsonSchemaType::findFieldTypeStorage()to respect that configuration
… 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 #3464042: Add ComponentAuditabilityTest 👍
Changes
- New:
hook_storage_prop_shape_alter(), with explicit test coverage (HookStoragePropAlterTest) and API docs - New:
CandidateStorablePropShape, the mutable variant ofStorablePropShape, used only for that alter hook. Has convenience to/from methods. - New:
media_library_storage_prop_shape_alter(), implemented by XB on behalf of Media Library, with explicit test coverage (MediaLibraryHookStoragePropAlterTest) - Improved:
StaticPropSource::randomizeValue()now has special handling for entity references, for reasons documented in detail - 🐛 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
EntityReferenceItemfield 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 updateStaticPropSource'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. - 👆 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: #3463996: [META] When the field type, storage/instance settings, widget, expression or requiredness for an SDC/code component prop changes, the Content Creator must be able to upgrade - ✅ … this means two crucial
@todos added by #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings are now resolved
User interface changes
- Without Media Library installed
-

- With Media Library installed
-

| Comment | File | Size | Author |
|---|---|---|---|
| #12 | Screenshot 2024-08-02 at 4.32.50 PM.png | 62.53 KB | wim leers |
| #12 | Screenshot 2024-08-02 at 4.32.18 PM.png | 70.22 KB | wim leers |
| #8 | Screenshot 2024-08-01 at 3.56.54 PM.png | 54.01 KB | wim leers |
Issue fork experience_builder-3462709
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
Comment #2
wim leers"could", but why? There seems to be plenty of issues with front-end work to be done?
Comment #3
lauriiiI filed this issue during our weekly planning with you, based on instructions I received from you. 🤔 I agree that the issue summary could use some more context but I don't have any more information than you to expand on this.
Comment #4
wim leersYes, I said we could do that if needed. It'd unblock front-end discovery work on #3454173: Media Library integration (includes introducing a new main content renderer/`_wrapper_format`) if there were not enough actionable work in #3450592: [META] Front-end Kanban issue tracker. But there's ~half a dozen of critical issues ready to be worked on there.
I'll self-assign to revisit this during this sprint if those half dozen front-end issues have landed. But I'd prefer to not do this, and instead just do #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings. But we first need to get on the same page on that.
Comment #5
wim leersDiscussed with @lauriii. Now that #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings is virtually done, it makes sense to keep this blocked on #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings.
Now there's a much more precise plan of action! 👍
Comment #6
wim leers#3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings is in.
Comment #8
wim leersStill cleaning this up (hacked my way to success!), but I've gotten to the point where the

\Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidgetdoes load 😊Comment #9
bnjmnmThis will 100% need a dependency on the media module since we're assuming it is there, and even though it's not necessary to function the media library module should probably also be there since that's the widget we indend to use.
Comment #10
wim leers💯
Comment #11
wim leersI just introduced
hook_storage_prop_shape_alter()+ docs + infra — that fixes a@todoand minimizes the hardcoded nature.It is also an essential step towards contrib extensibility/overridability, which we already knew in #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings that we'd have to add.
Retitling accordingly.
Comment #12
wim leersReview suggestion: see the section in the issue summary for the big picture. That should help you review this.
Alternatively: the commit history walks you through it via the commit messages.
Comment #13
wim leers🤣🙈
Comment #14
wim leersThis conflicted with #3462247: Start passing entity type/entity ID context to SdcController from the FE on the back-end side, and then tests failed here, due to a regression on the front-end side introduced by that same issue/MR: #3462247-17: Start passing entity type/entity ID context to SdcController from the FE. Trivial fix though :)
Comment #16
tedbowThis looks good. I made 2 very minor changes
Comment #17
wim leers@bnjmnm in #9: I know I agreed with you in #10, and then I didn't do it!
The reason is simple though:
media_library_storage_prop_shape_alter()literally only is executed if the Media Library module is installed — even though that hook is implemented inexperience_builder.module. It's simply implemented by XB on behalf of Media Library. It's a technique we've often used in experimental modules in Drupal core :) Hence also the without/with screenshots in the issue summary!And as a bonus: that alter hook implementation checks even something more granular, to be on the safe side:
Comment #19
wim leers