Problem/Motivation
The Embed component dialog shows an enum prop's raw values in its select, even when the component labels them with meta:enum. For core's navigation:title, "HTML tag for title" offers "h1" … "span" instead of "Heading 1" … "Inline". The labels are not translated either, while core makes meta:enum labels translatable with the prop's x-translation-context.
Reproduced on SDC Embed 1.x (same code as 1.2.0) with Drupal 11.4.9.
Steps to reproduce
- Install Drupal with the Standard profile and enable SDC Embed. At Configuration > Text formats and editors > Full HTML, add the "Embed component" button and enable the "Embed Single Directory Components" filter.
- At
/admin/config/content/sdc-embed, check "Include components provided by modules". - Create a Basic page in Full HTML, click "Embed component" and choose "Title — navigation".
- Open the "HTML tag for title" select.
Expected: Heading 1, Heading 2 … Heading 6, Inline, translated in the interface language.
Actual: h1, h2 … h6, span.
The same happens for an enum prop of a component nested in a slot.
Root cause
SdcEmbedDialog::buildPropField() and SdcSlotSource::buildPropField() build the options with array_combine($prop['enum'], $prop['enum']), and SdcDiscovery::normalizeProps() drops meta:enum.
Proposed resolution
SdcDiscovery::normalizeProps() adds options to an enum prop, keyed by value. Each value takes its meta:enum label, translated as ComponentMetadata::parseSchemaInfo() does (TranslatableMarkup with the prop's x-translation-context), or the value itself when the prop declares no label. Undeclared values are not passed through translation, so they are not added to interface translation as source strings.
Both buildPropField() methods use options, falling back to the bare values for a component added by an AlterEditorComponentsEvent subscriber without them. The stored value does not change.
Checked in the browser with navigation:title: in English the select shows "Heading 1" … "Inline"; with Portuguese as the interface language and translations for "Heading 1" in the "HTML tag" context, it shows the translations; choosing "Inline" still stores {"html_tag":"span"}. The nested component select in a slot shows the same labels.
The MR adds SdcDiscoveryTest::testEnumOptionsUseMetaEnumLabels(), which checks the labels, the translation context and the fallback to the value. It fails without the fix.
Remaining tasks
Review.
User interface changes
Enum selects in the dialog show the meta:enum labels instead of the raw values.
API changes
None. The normalized prop gets a new options key; enum stays.
Data model changes
None.
AI usage
AI-Generated: Yes. I used Claude Code (Anthropic) to write the fix, the unit test and a first draft of this summary. I reproduced the bug and verified the fix in the browser, in English and Portuguese, reviewed the code, and confirmed the new test fails without the fix and passes with it.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | sdc-3630631-fractional-enum.patch | 2.86 KB | c2h2o5 |
| #3 | sdc_embed-enum-meta-labels-3630631-3.patch | 6.01 KB | tiago |
Issue fork sdc_embed-3630631
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 #3
tiago commentedMR !5 is ready for review and its pipeline passes.
Attached below is the MR diff as a patch for 1.2.0.
Comment #4
tiago commentedComment #6
c2h2o5 commentedHier an patch that fixes fractional numeric enum values being truncated when used as PHP array keys. Values such as 0.5 and 0.75 previously became the same key, causing options to overwrite each other and preventing their meta:enum labels from being resolved.
Enum values are now cast to strings before looking up labels and building options. A regression test verifies that fractional values remain distinct, both with and without labels.
Comment #9
c2h2o5 commented