- Issue created by @griffynh
- 🇫🇷France pdureau Paris
For your information, in UI Patterns 2 → , we use "meta:enum" which is not an official standard but supported by some popular projects:
props: type: object properties: position: type: string enum: - top - bottom "meta:enum": top: Top bottom: Bottom
If an item is in
enum
but not inmeta:enum
, its label will be the item string
If an item is inmeta:enum
but not inenum
, it is ignored.It would be great to stay compatible.
- 🇫🇷France pdureau Paris
So, we have agreed on using
meta:enum
and leveraging this information and the related translations (fromlocale
module API) is up to the display building tools like UI Patterns 2 and Experience Builder.Also, adding
meta:enum
to the documentation will be done in this issue 🌱 Clarify SDC documentation by toning down Twig blocks promotion Active .So, what can we do in Core?
- Add a mention of
meta:enum
in ComponentMetadata? Ans some light logic? - Add
meta:enum
to some of our test components - Add a specific test about
meta:enum
? which one?
- Add a mention of
- 🇺🇸United States mradcliffe USA
I performed Novice Triage on this issue. I added the Novice issue tag because we can update the issue summary and potentially start. We need to come up with a good test for the change.
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
#4 referenced https://github.com/adobe/jsonschema2md, so I went to look for an example there, and found one that's sufficiently silly to be fun:
"string_pattern": { "type": "string", "description": "A string following a regular expression", "pattern": "^ba.$", "examples": ["bar", "baz", "bat"], "meta:enum": { "baa": "the sounds of sheeps", "bad": "German bathroom", "bag": "holding device", "bah": "humbug!", "bam": "a loud sound", "ban": "don't do this", "bap": "a British soft bread roll", "bas": "from ancient Egyptian religion, an aspect of the soul", "bat": "…out of hell", "bay": ", sitting by the dock of the" },
— https://github.com/adobe/jsonschema2md/blob/f3b5773eb610130891503c1cf71b...
So let's use that one (or a variation thereof).
By the way, ✨ Add an icon management API Active also used
meta:enum
:* If an `enum` is set, then the select is used: * - enum => #type = select and #options * The key `meta:enum` is used to support description for each enum. * * @internal * This API is experimental. */ class IconExtractorSettingsForm {
- First commit to issue fork.
- Merge request !11791#3493070: SDC `enum` props should have translatable labels: use `meta:enum`' → (Open) created by penyaskito
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
@pdureau: as an SDC maintainer, what do you think about https://git.drupalcode.org/project/drupal/-/merge_requests/11791/diffs#n...?
- 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
Added an end-to-end test (as a kernel test). This is ready from my POV.
The test failure is happening in HEAD too. - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
I think this is in the final stretch now! This needs a change record, plus 2 clarifications, plus 1 code clarity nit by Lee that I +1'd.
- 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
Fixed everything from Wim review, added change record draft.
- 🇺🇸United States phenaproxima Massachusetts
longwave → credited phenaproxima → .
- Status changed to Needs work
9 days ago 8:56pm 5 May 2025 - 🇬🇧United Kingdom longwave UK
Discussed this with @penyaskito and @effulgentsia. We came up with two alternative options; we can still bikeshed over the exact names but JSON Schema has no opinion on how to handle extensions, so we need to make our own decision here.
- As proposed by @pdureau in #4 we use
meta:enum
for human readable enum values, and some othermeta:
prefix key for translation contexts. - Or, as per this JSON Schema blog post where we
added x-formatting-context to Experience Builder
📌
`StringSemanticsConstraint::MARKUP`: agree how SDC prop JSON schema can convey it should be markup, and
Needs review
we use something like
x-enum-labels
for human readable enum values andx-translation-contexts
for translation contexts.
@pdureau (or anyone else!) do you have any strong preferences or guidance on this?
- As proposed by @pdureau in #4 we use
- 🇫🇷France pdureau Paris
I would prefer a policy where we avoid as much custom JSON schema annotation as possible:
- They are creating our own "island" in the JSON schema world
- They are tempting to be used as convenient workarounds on the SDC side instead of fixing the root cause in the application side.
x-formatting-context
is an example of such workaround, because we are asking the component author to add an annotation related to the UX of a specific display building tool he doesn't have to care about, instead of being focused only on its component's own UI model and logic.
That's why I like
meta:enum
. Yes, it is not part of the JSON schema specs, however:- it is not something we have invented, it is already used in opens source tools
- it is still describing the component and not some unrelated applicative stuff
- it looks like something special, we are not opening a Pandora box by normalizing
x-
annotations - it looks like it can be included in a future version of JSON schema
- 🇺🇸United States effulgentsia
That's why I like meta:enum. Yes, it is not part of the JSON schema specs, however...it is not something we have invented, it is already used in opens source tools
But is that future-compatible considering https://json-schema.org/blog/posts/the-last-breaking-change? When a stable json schema version is released and tools adopt it, are we expecting https://github.com/adobe/jsonschema2md to provide the vocabulary/schema for it, and then we'll change all of our SDCs to reference it?
If we do stick with
meta:enum
given its prior art, then what about translation context? If that's one that we are inventing here and not copying from other OSS tools, then I think that one needs anx-
prefix given JSON schema's move away from unknown keywords not prefixed with that. Perhapsx-translation-context
? - 🇺🇸United States effulgentsia
x-formatting-context is an example of such workaround, because we are asking the component author to add an annotation related to the UX of a specific display building tool he doesn't have to care about, instead of being focused only on its component's own UI model and logic
My reply to this is tangent to this issue, but I do want to note that I disagree with this characterization. If an SDC defines an HTML-containing prop, and then has Twig code that renders that prop inside a
<p>
tag or has CSS that assumes that what's in that prop is only inline formatted content, then it's the component's own UI logic that dictatesx-formatting-context: inline
. - 🇺🇸United States effulgentsia
and then we'll change all of our SDCs to reference it?
Maybe that won't be necessary since SDCs reference the schema in Drupal core, so we'll be able to update just that central one when the time comes?
- 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
Thanks everyone for the reviews and the conversations.
Given all the arguments, I'm gonna continue with the implementation with these in mind:
- We want to use "meta:enum", even if not very future-proof, for consistency with other frameworks frontend devs might be familiar with.
- "meta:enum" shouldn't be required. We default to the enum keys if not provided.
- We will add
x-translation-context
at the prop level. We will take into account this might get promoted to the component level, so we want to "cascade". If no translation context found, we use an empty string.
So an example of an enum prop would be:
enum: - info - success meta:enum: info: Information success: Success x-translation-context: "Status icon"
- 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
Update IS with latest discussions agreements.
- 🇬🇧United Kingdom longwave UK
+1 for the decision in #38, given we have seen prior art in using
meta:enum
but that also thex-
prefix is seemingly preferred by the JSON Schema team for extensions.I think cascading the context makes sense too. It seems likely that you would want the same context to be applied across all translatable strings in the prop (and certainly all cases in the enum), but you might also want it to cover the whole component without having to repeat yourself.
@pdureau are you OK with this?
The Needs Review Queue Bot → tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.
- 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
Don't know why the bot complained, gitlab didn't, and rebase was automatic:
$ git rebase 11.x Successfully rebased and updated refs/heads/3493070-sdc-metaenum.