Problem/Motivation

SdcPropToFieldTypePropMatcher was developed in https://git.drupalcode.org/project/experience_builder/-/tree/research__d... and was merged into 0.x as one of the starting points.

It proved matching SDC's prop's JSON schema shapes against Field Type's props + validation constraints was possible. But it didn't implement everything.

Proposed resolution

  1. Match existing field instances (DynamicPropSource) using the Choice constraint? Note that \Drupal\experience_builder\SdcPropJsonSchemaType::toDataTypeShapeRequirements() already does this:
    …
          SdcPropJsonSchemaType::STRING => match (TRUE) {
            array_key_exists('enum', $schema) => new DataTypeShapeRequirement('Choice', [
              'choices' => $schema['enum'],
            ], NULL),
    …
    

    → what's missing is that the list_string field type does not yet generate the appropriate validation constraints! Even though It does implement \Drupal\options\Plugin\Field\FieldType\ListItemBase::getPossibleValues(), which is supported not by the Choice constraint, but by the AllowedValues constraint, which is almost the same. So perhaps the code above should be updated to match against that constraint instead?

User interface changes

None.

CommentFileSizeAuthor
#9 adapter-mapping.png71.92 KBlauriii
Command icon 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

Wim Leers created an issue. See original summary.

tedbow’s picture

Assigned: Unassigned » tedbow

Looking into this

tedbow’s picture

Title: Add support for matching SDC prop shape: {type: string, enum: …} » [PP-1] Add support for matching SDC prop shape: {type: string, enum: …}
Status: Active » Postponed
wim leers’s picture

Title: [PP-1] Add support for matching SDC prop shape: {type: string, enum: …} » Add support for matching SDC prop shape: {type: string, enum: …}
Related issues: +#3458580: Document in great detail where constraints for data leafs is authoritatively defined

See #3458580-5: Document in great detail where constraints for data leafs is authoritatively defined — that's in, but it might still be insufficient. I was unable to tell based on that issue summary + this issue.

wim leers’s picture

Assigned: tedbow » Unassigned
wim leers’s picture

Title: Add support for matching SDC prop shape: {type: string, enum: …} » [PP-1] Add support for matching SDC prop shape: {type: string, enum: …}
Priority: Critical » Major
Related issues: +#3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings

Actually, I think this would no longer be in the critical path once we do #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings along with predefining the needed PropShapeInputs for some enum-using SDCs.

Demoting priority.

wim leers’s picture

I don't think it is likely that a {type: string, enum: …} SDC prop schema would be able to be supported by existing structured data (i.e. existing entity fields). IOW: a DynamicPropSource for them seems to be a rather edge case need.

But I do think it's a hard requirement that SDCs with such props are supported, so supporting StaticPropSources for them is crucial.

In working on #3461499: Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings, I realized that the "matching" infrastructure makes more sense for DynamicPropSource, but far less so for StaticPropSource. And in fact … I've got exactly this use case working there: https://git.drupalcode.org/project/experience_builder/-/merge_requests/1...

lauriii’s picture

Issue summary: View changes
StatusFileSize
new71.92 KB

I don't think it is likely that a {type: string, enum: …} SDC prop schema would be able to be supported by existing structured data (i.e. existing entity fields). IOW: a DynamicPropSource for them seems to be a rather edge case need.

This is indeed a scenario which doesn't work very well with the current DynamicPropSource concept because mapping enum values 1:1 introduces tight coupling between the data model and the components. I'm glad we're getting to the weeds because it helps us discover these scenarios.

For this scenario, we'd need some concept of mapping values. I'm wondering if it would make sense to implement this as an adapter:

wim leers’s picture

That's what adapters are indeed for.

lauriii’s picture

Thank you for confirming that @Wim Leers! I was worried that this would be challenging from technical perspective, and felt more confident about designing a UX for this. I would not say that it's a trivial UX task but it should not be insurmountable. I think that's a good sign given that we both feel good about this *high-five* 😊

wim leers’s picture

Title: [PP-1] Add support for matching SDC prop shape: {type: string, enum: …} » [later phase] Add support for matching+adapting existing field instances against complex SDC prop shapes like {type: string, enum: …}
wim leers’s picture

Title: [later phase] Add support for matching+adapting existing field instances against complex SDC prop shapes like {type: string, enum: …} » [later phase] Support matching enum SDC prop shapes against DynamicPropSources, not only generating StaticPropSources
Component: Page builder » Shape matching
Issue summary: View changes
Parent issue: #3450586: [META] Back-end Kanban issue tracker »
Related issues: +#3450496: Clarify the "shape matching" bits: namespaces, `CODEOWNERS` and as issue queue component

Now that #3450496: Clarify the "shape matching" bits: namespaces, `CODEOWNERS` and as issue queue component landed, the remaining work here became clearer:

wim leers’s picture

Because >50% of the https://git.drupalcode.org/project/experience_builder/-/merge_requests/73 MR won't be relevant anymore when #13 gets worked on eventually, I closed it.

3 tiny bits will still be relevant:

  1. https://git.drupalcode.org/project/experience_builder/-/merge_requests/7...
  2. https://git.drupalcode.org/project/experience_builder/-/merge_requests/7...
  3. https://git.drupalcode.org/project/experience_builder/-/merge_requests/7...

Now that I've explicitly linked those bits, it's definitely justified to have that MR closed.

wim leers’s picture

Version: » 0.x-dev
Issue tags: +stable blocker
wim leers’s picture