Tighten validation of `experience_builder.generated_field_explicit_input_ux: prop_field_definitions.[%key].expression`

Created on 27 May 2025, 7 days ago

Overview

In HEAD:

Proposed resolution

  1. Make this test coverage (copy/paste into ComponentValidationTest) pass:
      /**
       * @testWith ["ℹ︎non_existing_field_type␟value", "Invalid expression: the \"non_existing_field_type\" field type does not exist."]
       *           ["ℹ︎string␟non_existing_field_property", "Invalid expression: the \"string field\" type does not have a field property \"non_existing_field_property\"."]
       *           ["nonsense", "Invalid structured data expression."]
       *           ["ℹ︎␜entity:node␝title␞␟value", "A \"FieldPropExpression\" was provided, but expected one of \"FieldTypePropExpression\", \"FieldTypeObjectPropsExpression" or \"ReferenceFieldTypePropExpression\"."]
       *
       * @see `type: experience_builder.generated_field_explicit_input_ux`
       * @covers \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\GeneratedFieldExplicitInputUxComponentSourceBase
       */
      public function testInvalidPropFieldDefinitionExpression(string $expression, string $expected_message): void {
        $settings = $this->entity->getSettings();
        $settings['prop_field_definitions']['text']['expression'] = $expression;
        $this->entity->setSettings($settings);
        $this->assertValidationErrors(['settings.prop_field_definitions.text.default_value' => $expected_message]);
      }
    
  2. Add this to config schema:
    diff --git a/config/schema/experience_builder.schema.yml b/config/schema/experience_builder.schema.yml
    index 5f8d95ecb..9e8fd23e8 100644
    --- a/config/schema/experience_builder.schema.yml
    +++ b/config/schema/experience_builder.schema.yml
    @@ -394,13 +394,15 @@ experience_builder.generated_field_explicit_input_ux:
                   type: field.value.[%parent.%parent.field_type]
                 # @todo Add validation constraint because this is only *conditionally* nullable: if the SDC prop is optional
                 nullable: true
    -          # The default value must be retrievable
    +          # The default value must be retrievable.
               expression:
                 type: string
    -            label: ''
    -            constraints: { }
    -            # @todo Add `StructuredDataPropExpression` validation constraint that fails if StructuredDataPropExpression::fromString() fails
    -            # StructuredDataPropExpression: [field_type]
    +            label: 'The expression'
    +            constraints:
    +              ValidStructuredDataPropExpression:
    +                - FieldTypePropExpression
    +                - FieldTypeObjectPropsExpression
    +                - ReferenceFieldTypePropExpression
     
     experience_builder.component_source_settings.js:
       constraints:
    
  3. Create the ValidStructuredDataPropExpression validation constraint to make the above test coverage pass :)

User interface changes

None.

📌 Task
Status

Active

Version

0.0

Component

Config management

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024