Overview
Quoting @lauriii from #3501902-65: Adding the Image component results in a state considered invalid:
I'm getting this error when I try to place "Container" element from demo design system. It has an optional image without an example.
AssertionError: assert(\is_array($this->value)) in assert() (line 78 of /var/www/html/web/modules/contrib/experience_builder/src/PropSource/FallbackPropSource.php).
Quoting @longwave from #3501902-66: Adding the Image component results in a state considered invalid:
the problem with the demo Container is that it specifies an image without an example:
# Don't put examples as this is used with and without images. image: $ref: json-schema-definitions://experience_builder.module/image type: object title: Imagebut Experience Builder's
imageschema says thesrcproperty is required:"image": { "title": "image", "type": "object", "required": ["src"], "properties": { "src": { "title": "Image URL", "$ref": "json-schema-definitions://experience_builder.module/image-uri" },This causes a validation error because when you first add the component the image doesn't have a src. If an example was specified (as in the XB image component) then we use that as the fallback, but there is nothing to fall back to here either.
Proposed resolution
- Allow GeneratedFieldExplicitInputUxComponentSourceBase::clientModelToInput() to skip resolving a value when a prop is not set.
- Prevent computation of the default resolved value from crashing if no example is present.
User interface changes
None.
Issue fork experience_builder-3507641
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:
- 3507641-validate-examples
changes, plain diff MR !688
- 3502902-simpler
compare
Comments
Comment #2
lauriiiIt must be possible to provide components with optional image fields without a default value, hence empty examples must be considered a valid schema for optional images.
But in this case
examples[0]doesn't exist: https://git.drupalcode.org/project/demo_design_system/-/blob/1.0.x/stars... 🤔Comment #3
lauriiiComment #5
wim leersCrediting @mherchel for #3507543, which is a duplicate. See my response at #3507543-3: Single broken component can break XB list of all components.
Comment #6
wim leersComment #8
wim leers#3507749: Clarify default 'resolved' vs 'source' value logic in GeneratedFieldExplicitInputUxComponentSourceBase::getClientSideInfo() is in! That'll make this MR much simpler! :D
Comment #9
wim leers🏓
Comment #10
longwaveThis actually solves #2 and not the original problem described, so tagging for issue summary update.
This works locally with the
image-no-exampleand SDDS components no longer crash for me, but some of the other SDDS components are acting strangely for me locally so this needs some more testing before it's ready to go in.Comment #11
longwaveUnassigning for now, will pick up again next week.
Comment #12
wim leersWill review Monday.
Comment #13
wim leersOther things took priority.
Comment #14
longwaveSince I moved the check to earlier then it seems the filtering is no longer needed, only the explicit
continue, plus the fix to allow missing examples.Updated the IS and migrated the original issue to #3508725: ComponentMetadataRequirementsChecker::check() should validate that the example(s) actually match the JSON schema
Comment #15
longwaveAssigning to Wim for review.
Comment #16
wim leersThis looks GREAT!
But I'd like to see slightly more test coverage. So that we never have to revisit #3501902: Adding the Image component results in a state considered invalid nor anything "image prop shape"-related. 🤞
Comment #18
wim leersFYI: added the (trivial) comprehensive test coverage I wanted: https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... — good to go now!
Why? As I wrote in #16: I don't ever want to revisit this again! 😅
Comment #20
wim leersComment #21
nagwani commentedComment #22
wim leers