Overview
Enum vales do not have (translatable) labels.

We need human-readable equivalents, and those equivalents must be translatable (using Drupal's interface translation mechanism).
⚠️ This should not be XB-specific.
⚠️ Out-of-scope here: translatability. Nothing in XB is translatable yet today. This will add the necessary infrastructure to make it feasible later 👍
Proposed resolution
- Fix this in core first: implement #3493070-10: SDC `enum` props should have translatable labels: use `meta:enum`.
- Then, port that core MR to XB, with the following changes:
- XB should perform the equivalent of these in
\Drupal\experience_builder\ComponentMetadataRequirementsChecker:
- INFRA: Update
\Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo()to trigger a deprecation error when anenumis encountered without a correspondingmeta:enum - INFRA: Update
\Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo()to trigger aComponentDoesNotMeetRequirementsExceptionwhen ameta:enumis encountered whose keys do not match (i.e. are a subset or superset) the values listed in the correspondingenum.
… but rather than deprecating or a logic exception, it will simply become a hard requirement for XB.
- INFRA: Update
- XB must support this not only for SDCs, but also for its "in-browser code components" (aka
JavaScriptComponentconfig entities), which use the same metadata structure as SDCs.For that, see the attached config schema patch.
If there is no
meta:enumpresent, the value will fallback to theenum. - Modify
\Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent()to also create aenumprop. This should first fail validation (422 response), then upon adding the matchingmeta:enum, it should pass validation.This is XB's equivalent for
- TEST: kernel test asserting that a
meta:enumnot matching theenumtriggers aComponentDoesNotMeetRequirementsException
- TEST: kernel test asserting that a
- XB must change the logic in
\Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType::toDataTypeShapeRequirements()to do the equivalent of
- INFRA: add a
getEnumOptions(string $prop): array<string, TranslatableMarkup>method to\Drupal\Core\Theme\Component\ComponentMetadatainspired byui_patterns'\Drupal\ui_patterns\EnumTrait::getEnumOptions(). (The thing thatui_patternsdoes not yet do is pass it through Drupal'st().)
That means changing e.g.
SdcPropJsonSchemaType::STRING => match (TRUE) { array_key_exists('enum', $schema) => new DataTypeShapeRequirement('Choice', [ 'choices' => $schema['enum'], ], NULL),to actually use the
meta:enumvalues.(Note that here, they must NOT be translated — translation must happen at runtime — this corresponds to a
FieldConfigconfig entity aka configuration.) - INFRA: add a
- Now update
ui/tests/e2e/prop-types.cy.jsto prove that the labels for the enum indeed appear in the UI, by updating theit('Enum (select) - string', () => {test case.This is XB's equivalent for
- TEST: kernel test asserting that 2 identical
type: string, enum: […]props can have different translations for the same enum values. For example: a''enum value results inSame windowfor thetargetprop and inNonefor arelprop.
→ verifies it works end-to-end, and supports translation contexts
- TEST: kernel test asserting that 2 identical
- XB should perform the equivalent of these in
User interface changes
- Any SDC that has
enumwithout the necessarymeta:enumwill no longer be available to XB users, and will now appear in the list of disabled XB components at/admin/appearance/component/status, with an explanation of why. - Any SDC (or code component) that does have both
enumand a matchingmeta:enumwill now see those labels in the component inputs form on the right-hand side. - Any SDC (or code component) that does have
enumbut notmeta:enumwill have theenumvalues. (eg.my-bannerormy-ctain core)
Steps to test
Is useful to enable xb_test_sdc and _sb_test_code_components modules. There are created components with and without meta:enums and with mismatched meta:enums.
- Include a SDC with
enumandmeta:enumconfigured and confirm that the values that appear are the labels configured inmeta:enum - Include a SDC with
enumand withoutmeta:enumconfigured and confirm that the values that appear are the values configured inenum - Enable the module
xb_test_sdc, navigate to/admin/appearance/component/statusand confirm the reason whysdc.xb_test_sdc.component-mismatch-meta-enumwasn't enabled is because theenumandmeta:enumvalues mismatch - In both components, modify the values and confirm that the changed values preview correctly but is not changed in the page without saving.
- Confirm that in both cases, after saving the page (review x changes, publish all changeS), the values display correctly.
-
Create a new code component (can be in a module insideEnable theconfig/installand can be the one I've attached)xb_test_code_components_with_enumscode component and confirm that the field with meta:enum has Capitalized values, and the one with onlyenumhas the plain values. Play around by adding or removing enums and meta:enums in the config (in that case the component must be first exported toconfig/syncand be modified there. - Confirm the same tests in this code component than the ones done in the Single Directory Component
Follow-up needed:
- UI for defining key and values for enums in js components
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | Screenshot 2025-07-04 at 2.54.23 PM.png | 192.32 KB | wim leers |
| #51 | Screenshot 2025-07-04 at 2.51.32 PM.png | 153.2 KB | wim leers |
| #20 | experience_builder.js_component.with_enums.yml | 1.09 KB | isholgueras |
| #2 | 3516602-config-schema.patch | 2.03 KB | wim leers |
Issue fork experience_builder-3516602
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
Comment #2
wim leersConfig schema changes necessary for XB's
JavaScriptComponentconfig entities attached to help get this going 👍Comment #3
wim leersComment #5
wim leersFixing markup.
And crediting @pdureau, for our collaboration at DrupalCon Atlanta to ensure XB and UI Patterns 2 are aligned 😊
Comment #8
wim leersExciting to see #3493070: SDC `enum` props should have translatable labels: use `meta:enum` be ready for review! Now let's get this going 😁 (Because XB can't wait for core to ship this in a release.)
Comment #9
isholgueras commentedComment #10
isholgueras commentedComment #11
isholgueras commentedComment #12
penyaskitoThis works and has good test coverage.
Comment #13
penyaskitoRe-reading IS I think Wim expected to implement the Code Components here too? 🤔🤔
Comment #14
lauriii+1 for the follow-ups mentioned in #12.
Comment #15
penyaskitoIt took me a while to figure out why we need any change at all for JS Component.
So documenting it step by step.
Right now, the site builder will generate their prop, and select "List: string".
They see a single textfield, named "Value", with placeholder "Enter a text value", where they input their values one by one, and select the default one.
That generates:
One we enable the component, that transforms to:
So if they input a friendly label, that's what they get. For translation, we need to translate that config entity.
There's no way we can do this right without having some value - label pair on the client, or document how their values will be generated (potentially like prop names already are). In that case we might indicate in the UI that we expect labels, not values, and ideally print the value so they can copypaste that into the code editor.
If we do that in the client, they will post the pairs (or the value can be easily calculated from the label, as prop names do). For simplicity, we use the same format than SDC (see props in js_component above).
And when we have that, it's the client who would send the enum and the meta:enum (optionally we might want a x-translation-context, or generate one server side, but that's definitely for another follow-up), and we will have the same info than a "meta:enum" complete component (or an easy way to generate it server-side), which will generate the right config entity allowed_values pairs for e.g. translation.
Comment #16
penyaskitoI think this is ready if we split the code components part, which I moved to #3523680: JsComponents `enum` props should have human-readable labels: use `meta:enum`
Comment #17
penyaskitoWe'll work on JsComponents here.
Comment #18
penyaskitoComment #19
isholgueras commentedComment #20
isholgueras commentedComment #21
isholgueras commentedComment #22
isholgueras commentedComment #23
isholgueras commentedI wanted to add a new code component with 2 props, one with enums and another one with enums and meta:enums to have a yml file with this as an example.
We had tested it in
XbConfigEntityHttpApiTestbut I think having a code component in a yml is useful for testing and for new adopters to see how is done.I've also fixed issues with HEAD.
Steps to test, in Summary, is also updated.
Comment #24
isholgueras commentedIt needs to fix a complex conflict.
Comment #25
isholgueras commentedComment #26
wim leersPartial review, but I'm pretty sure I spotted some significant simplification potential? 😇
Comment #28
penyaskito#3493070: SDC `enum` props should have translatable labels: use `meta:enum` landed in time for 11.2.0
Comment #29
wim leers#28: 🎉🥳
Next up: make XB leap ahead of core by landing this MR … ⚠️ but because XB will not be able to require 11.2 until AFTER beta1, we need to be careful about how we approach it.
Comment #30
wim leersThis needs to make
meta:enummandatory for XB. 🙏 See the rationale.Comment #31
wim leersComment #32
penyaskitoComment #34
wim leersMerged in upstream, let's get this to passing tests so we can land it 🙏
Comment #35
isholgueras commentedComment #36
isholgueras commentedConflicts with
0.xfixedComment #37
wim leers@isholgueras is now (hopefully) AFK :)
Comment #38
penyaskitoAll tests passing 🎉
Something that doesn't have e2e tests is the code editor, but we need to fix it to at least send the same values in enum as meta:enum.
Bálint volunteered to write this.
@balintbrews For now I'd expect to send the same added values as labels. The only thing to take into account is replacing dots with underscores. Something like:
Comment #39
lauriiiI'm not entirely convinced that we should not allow SDCs without meta:enum to be used in XB because it is possible to achieve an acceptable UX without providing meta:enum, albeit not in all scenarios. For example, for margin-top, you could choose to provide options '4px', '6px', and '8px'. In this case the same value could apply both as the human readable and machine readable value.
We could still allow translating the enum options but keep the machine readable names consistent across translations or we could simply prevent translating these enums.
I don't think this needs to block this issue from being committed. It seems that we could loosen this requirement in future if this would require a non-trivial amount of work to change.
Comment #41
balintbrewsComment #42
penyaskitoI need to self-review this yet, but feels close. Bálint changes look good to me, thanks!
Comment #43
pdureau commentedHi Lauriii,
According to the #3528998: Follow-up: SDC `enum` props should have translatable labels: use `meta:enum`, all SDC prop with an
enumhas also a completemeta:enum. We made themeta:enumoptional at the YAML declaration level, but theparseSchemaInfo()method is aligning the values:Source: https://git.drupalcode.org/project/drupal/-/commit/166350f2acc649d60e4da...
Comment #44
penyaskitoThis is ready for further reviews.
Comment #45
wim leersAfter raising a single (but very important because affecting
Componentversions and update paths for component instances) concern, then thinking I was wrong and reverting, then actually realizing I might've been right, it took me a few hours of digging deep into how theoptionsmodule's field/widget infrastructure works, to find a better solution that overcomes all concerns and has the blessing of @penyaskito! (Just paired with him and demonstrated it.)Let me illustrate it using XB's
headingSDC'sComponentconfig entity's versions — start at the bottom of this example, because top = newest, bottom = oldest:Next: make the MR pass again, by updating all
component_versions all over the MR, because the differentsettingsin theComponentconfig entities that contain >=1enum-shaped prop cause a different deterministic version hash 😅Comment #46
wim leersGreen except e2e tests, hoping that @penyaskito can fix those. 😇
Epic work here! 👏
Still needs follow-up for updating the code component editor UI: https://git.drupalcode.org/project/experience_builder/-/merge_requests/8...
Comment #47
penyaskitoDidn't get to find why yet, but the enums aren't loading the default value/ set value correctly.
e.g.
Comment #48
penyaskitoWhat I've found is that this might be that we need some changes in the client UI that I didn't spot yet.
A symptom:
1. Add a heading component (has 2 enums)
2. Add a druplicon component
3. Edit the heading style + element props (enums)
4. Click on the druplicon. The form fails to load.
5. Back to heading, the style + elements have the defaults instead of our changes.
Comment #49
wim leersThanks, that's helpful. I suggest you switch to something else for a bit, it sounds like this has been a frustrating ride :/
Comment #50
penyaskitoI tested this and with this MR the values aren't set for any prop, not only enum, even when the SDC has no enums.
Comment #51
wim leersPaired with @penyaskito on this. We got closer.
/xb/api/v0/api/layout/node/1response contains this after placing a new Heading SDC:textprop, the client incorrectly sends thisNote how the original prop value remains present (left) and the value I actually entered is sent with the wrong key (right).
This is what's causing things to not work. This appears to be happening in
buildPreparedModel(), which is what generates the value forform_xb_props.Comment #52
penyaskitoThe last js component failures are because #3528998: Follow-up: SDC `enum` props should have translatable labels: use `meta:enum` avoids any way to provide meta:enums, overriding them even when set.
This is a problem when using
\Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\JsComponent::buildEphemeralSdcPluginInstancefor validating js components as sdc components.Comment #54
penyaskitoUpdated after #3534758: Remove "List: number" as an available shape in the code component editor, for now landed.
Comment #55
penyaskitoBack to green. Added the followup needed in IS.
Comment #56
wim leersThanks, @penyaskito! 🙏
https://git.drupalcode.org/project/experience_builder/-/merge_requests/8... → well done!
Just one final question/thing that needs to be updated: https://git.drupalcode.org/project/experience_builder/-/merge_requests/8...
Comment #57
wim leersFinally. 🥹
This was added in #3 but is obsolete, because core didn't end up adding any such infrastructure 😅
Comment #59
wim leersComment #60
wim leersI mean, obviously :D
Comment #61
larowlanGlad to see this go in. Mammoth effort
Comment #63
wim leersThis mammoth effort was indeed awesome to see land, but it didn't distinguish between SDCs and code components — it treated both equally.
That's how this ended up slowing down #3515074: Shape matching MUST work with the resolved equivalents of $refs AND must be compatible with core's upcoming $ref resolving in SDCs, because there a
type: string, format: uri, enum: …test-only SDC was introduced. And the inevitable periods in URLs then were incorrectly deemed invalid.So #3515074: Shape matching MUST work with the resolved equivalents of $refs AND must be compatible with core's upcoming $ref resolving in SDCs ended up refining what this did: it applied the "dot restriction" only to code components.