Leap ahead of #3493070 in core: SDC `enum` props should have human-readable labels: use `meta:enum`

Created on 1 April 2025, 1 day ago

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

  1. Fix this in core first: implement #3493070-10: SDC `enum` props should have translatable labels: use `meta:enum` .
  2. Then, port that core MR to XB, with the following changes:
    1. XB should perform the equivalent of these in \Drupal\experience_builder\ComponentMetadataRequirementsChecker:
      1. INFRA: Update \Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo() to trigger a deprecation error when an enum is encountered without a corresponding meta:enum
      2. INFRA: Update \Drupal\Core\Theme\Component\ComponentMetadata::parseSchemaInfo() to trigger a \LogicException when a meta:enum is encountered whose keys do not match (i.e. are a subset or superset) the values listed in the corresponding enum.

      … but rather than deprecating or a logic exception, it will simply become a hard requirement for XB.

    2. XB must support this not only for SDCs, but also for its "in-browser code components" (aka JavaScriptComponent config entities), which use the same metadata structure as SDCs.
    3. Modify \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent() to also create a enum prop. This should first fail validation (422 response), then upon adding the matching meta:enum, it should pass validation.

      This is XB's equivalent for

      1. TEST: kernel test asserting that a meta:enum not matching the enum triggers a \LogicException
    4. XB must change the logic in \Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType::toDataTypeShapeRequirements() to do the equivalent of
      1. INFRA: add a getEnumOptions(string $prop): array<string, TranslatableMarkup> method to \Drupal\Core\Theme\Component\ComponentMetadata inspired by ui_patterns' \Drupal\ui_patterns\EnumTrait::getEnumOptions(). (The thing that ui_patterns does not yet do is pass it through Drupal's t().)

      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:enum values.

      (Note that here, they must NOT be translated — translation must happen at runtime — this corresponds to a FieldConfig config entity aka configuration.)

    5. Now update ui/tests/e2e/prop-types.cy.js to prove that the labels for the enum indeed appear in the UI, by updating the it('Enum (select) - string', () => { test case.

      This is XB's equivalent for

      1. 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 in Same window for the target prop and in None for a rel prop.
        → verifies it works end-to-end, and supports translation contexts

User interface changes

  • Any SDC that has enum without the necessary meta:enum will no longer be available to XB users, and will now appear in the list of disabled XB components at /admin/structure/component/status, with an explanation of why.
  • Any SDC (or code component) that does have both enum and a matching meta:enum will now see those labels in the component inputs form on the right-hand side.
📌 Task
Status

Active

Version

0.0

Component

Component sources

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024