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.

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.

libbna made their first commit to this issue’s fork.

libbna’s picture

I have updated the ComponentValidationTest.php and .schema file as per the suggestions. For next steps I have to confirm that we will be creating "ValidStructuredDataPropExpression.php" and "ValidStructuredDataPropExpressionValidator.php" inside the /src/Plugin/Validation/Constraint , right?

thoward216’s picture

Assigned: Unassigned » thoward216
Status: Active » Needs work
wim leers’s picture

wim leers’s picture

Oops, during the rebase on top of 1.x I apparently somehow erased the authorship by @libbna! 😅 Crediting them already to ensure they are recognized for what they contributed :)

wim leers’s picture

Assigned: thoward216 » wim leers

@thoward216 is out today, I'd like to land something nice & simple for once before I go on PTO 😇

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community

  • wim leers committed 98e068be on 1.x authored by libbna
    Issue #3526716 by wim leers, libbna, thoward216: Tighten validation of `...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.