Tighten validation of `experience_builder.generated_field_explicit_input_ux: prop_field_definitions`

Created on 27 May 2025, 2 months ago

Overview

In HEAD:

          default_value:
            # TRICKY: this MUST be a sequence, to allow for a multi-value default for `type: array` prop shapes.
            type: sequence
            label: 'Default values'
            sequence:
              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

This issue is about adding that missing validation.

Proposed resolution

Take inspiration from:

  • XB's KeyForEverySdcProp validation constraint
  • core's NotNull validation constraint

โ‡’

  1. Add a new NotNullValueForEveryRequiredSdcProp validation constraint. That should be able to follow the lead of the logic for KeyForEverySdcProp's validator. However, that uses \Drupal\experience_builder\PropShape\PropShape::getComponentProps(), which only looks at shapes, not required vs optional. To do that, use
    assert($component_plugin instanceof Drupal\Core\Plugin\Component);
    $component_schema = $component_plugin->metadata->schema ?? [];
    $required_props = $component_schema['required'] ?? [];
    

    For each of $required_props, a key must exist in the sequence, and it must have a not-null value. That's the validation logic we need ๐Ÿ˜Š

  2. Add new ComponentValidationTest::testInvalidWidgetSettings() test that does
        $settings = $this->entity->getSettings();
        assert($settings['prop_field_definitions']['text']['default_value'] !== NULL);
        $settings['prop_field_definitions']['text']['default_value'] = NULL;
        $this->entity->setSettings($settings);
        $this->assertValidationErrors(['settings.prop_field_definitions.text.default_value' => 'a meaningfulerror message']);
    

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.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • 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

Merge Requests

Comments & Activities

Production build 0.71.5 2024