ComponentMetadataRequirementsChecker::check() should validate no prop is of type object

Created on 9 May 2025, 24 days ago

Overview

We don't support object shapes, so XB becomes unusable if there are object props.

In Drupal 11.2.0, navigation module provides a title SDC, which breaks XB.

icon:
  title: Icon
  type: object
  properties:
    pack_id:
      title: Icon Pack
      type: string
      default: navigation
    icon_id:
      title: Icon ID
      type: string
    settings:
      title: Icon Settings
      type: object
      default:
        class: toolbar-button__icon
        size: 20

Proposed resolution

  1. Add an SDC to the xb_test_sdc module with invalid example
  2. Update SingleDirectoryComponent::checkRequirements() to detect and disallow this
  3. Update \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testDiscovery() expectations

User interface changes

XB works when navigation is enabled.

πŸ“Œ Task
Status

Active

Version

0.0

Component

Component sources

Created by

πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

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

Merge Requests

Comments & Activities

  • Issue created by @penyaskito
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    I’d swear this was already working, but I guess not?! πŸ€ͺ

    Thanks to the solid test infra + @penyaskito’s excellent issue summary, I believe this is doable for a novice contributor 😊

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • First commit to issue fork.
  • Pipeline finished with Failed
    19 days ago
    Total: 3938s
    #497313
  • πŸ‡ΊπŸ‡ΈUnited States partyka
  • πŸ‡ΊπŸ‡ΈUnited States partyka

    Turns out there are already some SDC components, using "object" already committed to the `xb_test_sdc` testing

    Specifically these SDCs:

    tests/modules/xb_test_sdc/components/image-optional-with-example
    tests/modules/xb_test_sdc/components/image-optional-with-example-and-additional-prop
    tests/modules/xb_test_sdc/components/image-optional-without-example/image-optional-without-example.component.yml
    tests/modules/xb_test_sdc/components/image-required-with-example
    tests/modules/xb_test_sdc/components/image-required-with-invalid-example
    tests/modules/xb_test_sdc/components/image-required-without-example

    This was uncovered in a slack chat with @penyaskito.. It was also mentioned in the chat that an array of objects is OK.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Looking at config/schema/experience_builder.json_schema we can find that type: object is valid, but only if $ref is defined too:

        '$ref':
          # ⚠️ Note the absence of `requiredKey: false` here: XB does not (yet) support arbitrary `type: object` shapes, so
          # `$ref` is actually REQUIRED for such props!
    

    In /schema.json we can see the accepted values for $ref.

    So we should validate in ComponentMetadataRequirementsChecker::check that if type is object, $ref is present.

    Later we could actually validate that $ref is one of the valid values (only json-schema-definitions://experience_builder.module/image for now), but we probably want to leave that out for now.

    Updated the requirements in the issue summary.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Looking at config/schema/experience_builder.json_schema we can find that type: object is valid, but only if $ref is defined too:

    Correct. Because we don't have πŸ“Œ [PP-1] Support `{type: object, …}` prop shapes that require *multiple* field types Postponed yet. See \Drupal\experience_builder\JsonSchemaInterpreter\JsonSchemaType::computeStorablePropShape() and \Drupal\experience_builder\Hook\ShapeMatchingHooks::datetimeRangeStoragePropShapeAlter() β€” those are the two only object shapes currently supported by XB.

    Later we could actually validate that $ref is one of the valid values (only json-schema-definitions://experience_builder.module/image for now), but we probably want to leave that out for now.

    That is actually already handled in \Drupal\experience_builder\ComponentMetadataRequirementsChecker::check(), thanks to this bit:

          // Every prop must have a StorablePropShape.
          $component_prop_expression = new ComponentPropExpression($component_id, $prop_name);
          $prop_shape = $props_for_metadata[(string) $component_prop_expression];
          $storable_prop_shape = $prop_shape->getStorage();
          if ($storable_prop_shape instanceof StorablePropShape) {
            continue;
          }
          $messages[] = \sprintf('Experience Builder does not know of a field type/widget to allow populating the <code>%s

    prop, with the shape %s.', $prop_name, json_encode($prop_shape->schema, JSON_UNESCAPED_SLASHES));

  • Pipeline finished with Failed
    18 days ago
    Total: 1445s
    #498327
  • Merge request !1057Added an "Invalid" shape of type object. β†’ (Merged) created by wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Wow, looks like @partyka pretty much did everything needed here, but just didn't create an MR yet? :D

    Awesome, thanks so much! 🀩

  • Pipeline finished with Failed
    12 days ago
    Total: 984s
    #503080
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Lovely, thanks, @partyka! 😊

  • Pipeline finished with Skipped
    10 days ago
    #504624
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
Production build 0.71.5 2024