Overview

I'm creating a component and adding optional properties without a default value. This currently results in an error:


Proposed resolution

See #8.

User interface changes

Before
After
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

lauriii created an issue. See original summary.

lauriii’s picture

Issue tags: +sprint-candidate
wim leers’s picture

Title: Optional properties should not require examples » Code components: optional properties should not require examples
Component: Theme builder » Config management
Assigned: Unassigned » wim leers
Issue tags: -sprint-candidate +sprint
Related issues: +#3509037: JavaScriptComponent config entities' `examples` and `enum` do not respect the prop's type
wim leers’s picture

Issue tags: +Configuration schema

wim leers’s picture

Status: Active » Needs work

Tests are proving the problem now 👍

wim leers’s picture

This should use ComponentMetadataRequirementsChecker, which will also mean we'll get examples validated in the future automatically, too — thanks to #3508725: ComponentMetadataRequirementsChecker::check() should validate that the example(s) actually match the JSON schema.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Needs review
  1. New constraint validator that calls ComponentMetadataRequirementsCheckerfails in an interesting way!
  2. Realize it A) must only run after JsComponentHasValidSdcMetadataConstraintValidator has verified it works — this is not possible in Drupal's Symfony validation constraint setup. So: merge it.

    Then realize B) that it overlaps with \Drupal\experience_builder\Plugin\Validation\Constraint\IsStorablePropShapeConstraintValidator.

Solution: expand JsComponentHasValidSdcMetadata (+ rename) and remove IsStorablePropShapeConstraintValidator. Less precise validation errors, but simpler code. And it even makes this MR a net reduction in LoC!

💁‍♂️ We can work on making the validation errors precisely target the faulty property path value in the config entity later, if there is a need for that. Because the XB code component editor UI does not even allow creating invalid ones — so only people manually modifying JavaScriptComponent config entity YAML exports and then importing them will ever even see these errors.

P.S.: the Implicit conversion from float 3.14 to int loses precision PHP deprecation warning is due to a core bug: \Drupal\options\Plugin\Field\FieldType\ListItemBase::simplifyAllowedValues() uses the value of each list option as an array key. This works fine for strings and ints (both valid array key indices), but not floats. Try running $test = [3.14 => 'test']; on PHP >=8.1 and you'll see the same. I first thought this was caused by #3493070: SDC `enum` props should have translatable labels: use `meta:enum`, but it's not.

wim leers’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new259.8 KB
new206.38 KB

Manually tested in the UI, it works:

Before
After

👍

  • wim leers committed 73361f4a on 0.x
    Issue #3509186 by wim leers, lauriii: Code components: optional...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
nagwani’s picture

Issue tags: -sprint
wim leers’s picture

Component: Config management » Component sources

Status: Fixed » Closed (fixed)

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