Don't raise exception when an enum value is missing from meta:enum

Created on 8 June 2025, 16 days ago

Problem/Motivation

We merged ✨ Enum vales do not have translatable labels Active 3 days ago, and there is a mechanism which may cause troubles:

if (isset($prop_schema['enum'], $prop_schema['meta:enum'])) {
  $enum_keys_diff = array_diff($prop_schema['enum'], array_keys($prop_schema['meta:enum']));
  if (!empty($enum_keys_diff)) {
    throw new InvalidComponentException(sprintf('The values for the %s prop enum in component %s must be defined in meta:enum.', $name, $this->id));
   }
}

It forces component authors to add meta:enum items even for items which doesn't need a label distinct from the value.

For example:

type: string
enum: ["auto", "1", "2"]
"meta:enum":
  "auto": "Automatic"

Or:

 type: string
 enum: ["ul", "ol"]
 "meta:enum":
  ul: "ul (Default)"

I am afraid this decision is both making the component author life more difficult and breaking the projects already using this feature in a legit way.

Proposed resolution

So, let's :

  • Remove of this exception
  • Merge array_combine(enum, enum) to meta:enum
  • Removal of meta:enum items not found in enum (if not already the case) because the truth is in enum not meta:enum

API changes

Not a breaking change. In contrary, it increase compatibility with existing SDC themes.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

single-directory components

Created by

πŸ‡«πŸ‡·France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024