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

  1. 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.
  2. At /admin/config/content/sdc-embed, check "Include components provided by modules".
  3. Create a Basic page in Full HTML, click "Embed component" and choose "Title — navigation".
  4. 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.

Issue fork sdc_embed-3630631

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

tiago created an issue. See original summary.

tiago’s picture

StatusFileSize
new6.01 KB

MR !5 is ready for review and its pipeline passes.
Attached below is the MR diff as a patch for 1.2.0.

tiago’s picture

Status: Active » Needs review

c2h2o5 made their first commit to this issue’s fork.

c2h2o5’s picture

StatusFileSize
new2.86 KB

Hier 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.

  • c2h2o5 committed e1db13db on 1.x
    Issue #3630631: Preserve fractional enum option keys
    

  • c2h2o5 committed 85a5d9ae on 1.x
    Issue #3630631: Label enum prop options with their meta:enum labels in...
c2h2o5’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.