Closed (fixed)
Project:
Experience Builder
Version:
0.x-dev
Component:
Component sources
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Jan 2025 at 12:58 UTC
Updated:
10 Jun 2025 at 21:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersComment #3
heyyo commentedRelated issue with
examplesBy default XB adds a 'None' value to the SELECT OPTIONS, which is great like this no need to add a empty string in enum.
But it doesn't seem possible to set this None value as the default value.
What I tried:
- Not to add
examplesat all-
examples: []-
examples: ['']All of them return the same error
Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("[linno_theme:select/select] Does not have a value in the enumeration ["ratio-32x9","ratio-21x9"]. The provided value is: ""."). in Twig\Template->yield() (line 1 of themes/custom/linno_theme/components/select/select.twig).Comment #5
tirupati_singh commentedI'll look into this.
Comment #6
wim leersFYI this is thanks to
\Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel()'s:Comment #7
wim leersThanks, @tirupati_singh! Adding some related issues :)
Comment #9
tirupati_singh commentedHi all, I've created a new component called "CTA Button" to replicate the issue and confirm that it still persists. Below is the component.yml file:
I agree with @wim leers and @heyyo's point that
I also believe the empty string is unnecessary for the component props, as the "None" option provided by Drupal already covers this functionality.
To address the issue as per the comment #3, I removed the empty string value from enum. However, I’d prefer that we accept the "None" option provided by Drupal, rather than adding an empty string in enum.
By removing the empty string, this should also resolve issues with other components. I've attached before and after screenshots of the fix for reference.
Please review the MR changes and let me know if any further adjustments are needed or if there's a better solution to address the issue.
Thanks!
Comment #10
wim leers@tirupati_singh: Thank you so much for articulating a much clearer path forward than I did back in January when I created this issue! 👏❤️🙏
Comment #11
penyaskitoI was very against this, but definitely last IS update in #10 changed my mind. Thanks Wim!
There are examples in core (at least in core tests) using this, so we might need a core issue for fixing those.
Comment #12
wim leersYay, glad to read that! 😄
I don’t see why core SDCs would need to change though. They could, yes. But plenty of (core and contrib) SDCs won’t work in XB today. What is different about these? 🤔
That’s why we have the “Appearance -> Components -> Disabled Components” UI that provides the reason why a component is not compatible.
Comment #13
penyaskitoThe reason is exactly the point that changed my mind:
> This is an
abusemisuse of JSON Schema/SDCs. The optionality of a type: string, enum: … should be indicated by NOT listing it as a required prop.Core will be used as implementation reference for most devs. This is not only about XB support (even this issue should be focused on that and I'm offtopic), but about defining best practices.
Comment #14
wim leers👍 Makes sense!
Comment #15
thoward216 commentedMoving back to "needs work" and assigning myself to look into the failing tests.
Comment #16
thoward216 commentedComment #17
wim leersYou took a different approach than what's in the issue summary, @thoward216, and you had me first thinking it was genius, simple and elegant, but … I think I spotted some negative consequences: do you agree?
Either way, this definitely still needs explicit test coverage. I think:
type: string, enum: [""]— aka only a single enumerated value, that now won't be valid anymore — this is also the case that definitely doesn't work in your current approachtype: string, enum: ["funny", "", "strings", "here"]Comment #18
wim leersOh, and this should add a message in
\Drupal\experience_builder\ComponentMetadataRequirementsChecker::check(), to ensure there's a friendly message 👍Combined with the test SDCs I suggested above, that'd force you to update the test expectations in
\Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testDiscovery(), which will then prove the friendly message appears as needed/expected :)Comment #21
thoward216 commentedI've updated the approach here to match the proposed solution, added a new test SDC and updated tests as needed.
After updating the approach, a number of tests are now failing due to them using the SDC
sdc_test:my-ctaas this is now not compatible with XB. (as it contains an enum with an empty.) It appears it is used in some other tests which now error, due to the tests trying to use it. I'm not clear on the path forward for this yet.Comment #22
wim leers#21:
XB started early on with only SDC support. For pragmatic reasons, and to avoid painting ourselves into a corner decorated with our own assumptions, we relied on test SDCs in Drupal core. That includes
core/modules/system/tests/modules/sdc_test/components/my-cta/my-cta.component.yml, which now turns out to be a bit of a weird one.I see that there are 37 failing tests relating to
sdc_test:my-ctaafter the (necessary!) change this MR makes.The clearest possible failure is
… which is exactly right: this is saying that the
Componentconfig entity hasstatus: truebut it can't/shouldn't be because of the empty string enum value! 👍I suggest the following path forward:
sdc_test:my_ctais meaningless (i.e. "just some SDC"), simply pick another SDC. For example,experience_builder:headingorexperience_builder:my-hero(which both also have a few props) or evenexperience_builder:druplicon(which has zero props).sdc_test:my_ctaare tested/used for tests: replace it with another SDC that has similar props. For exampleContentTemplateDependencyTestused "my CTA" but could easily switch to "heading" and retain the same test coverage, even despite testing specific props (explicit inputs). Because the input that the test is centered around is atype: string, which is a prop shape that "heading" also contains 👍my-ctaoffered (essentially, a link: URL + text +targetattribute), then just add a "cta" or "link" SDC to XB itself.Comment #23
tirupati_singh commented@wim leers, thank you for the detailed feedback and insights — much appreciated!
Yes, I do agree with your assessment. You're absolutely right — I took a different approach by omitting "" from the enum instead of explicitly disallowing it. At first glance, it seemed like a clean and unobtrusive way to sidestep the HTML limitation, but I can now see the downside — particularly in cases where "" is explicitly included in a required field's enum. This results in an unusable form element, which defeats the purpose of validating the SDC in the first place.
After re-reviewing the changes in my merge request, I realized that the current fix does not fully resolve the issue, especially for props like
cta_icon1andcta_icon2.While the intention was to handle enums with empty strings more gracefully, the approach I took (silently omitting "") doesn't correctly address all problematic cases. For instance:
Both of these cases still result in invalid for below component props
Thanks again for the clear explanation — it’s really helped clarify the situation. I'll adjust the implementation to explicitly disallow "" in enums and ensure proper test coverage for these cases.
Comment #24
tirupati_singh commentedThanks @thoward216 for the quick implementation of the requested changes. I’ve been reviewing the updated merge request with the feedback incorporated, but I’m encountering an issue while testing it with the same component props mentioned in comment #23.
When I use the component props as follows (from the earlier example):
I did not encounter the specific error message ('Prop "%s" has an empty enum value.', $prop_name) in the ComponentMetadataRequirementsChecker class, after the feedback was incorporated and the changes were made in the MR. However, I am now encountering a different issue in the Experience Builder UI. The error message displayed is: "An unexpected error has occurred while rendering the component's form." I’ve attached a screenshot for reference.
Could you please suggest any specific steps or checks I should follow when creating or testing the component? If there’s anything I might have missed or overlooked in the process, I’d really appreciate it.
Thanks!
Comment #25
thoward216 commented@wimleers - thanks for the context and suggested path forward in #22 will take a look into this.
@tirupati_singh - I've pulled in the latest commit locally and tested your component in #24 and it appears to work as expected, it does not show in the component library in experience builder and appears within the "disabled" section under "/admin/appearance/component/status" with the reasons - see screenshot. - Was the component already placed within experience builder and saved?
Comment #27
wim leersMy bet too :)
@thoward216 Just confirming … you are unblocked, right? 🤞
Comment #28
thoward216 commented@wimleers thanks, yes I'm unblocked on this.
Comment #29
thoward216 commentedTests are now all passing with the updated approach. Moving to needs review.
Comment #30
wim leersSooooooooooo very close! 😄
Comment #31
thoward216 commentedComment #32
wim leers🕺
Comment #34
wim leers