Overview
\Drupal\canvas\Plugin\Canvas\ComponentSource\GeneratedFieldExplicitInputUxComponentSourceBase::getExplicitInputDefinitionsAsConfigSchemaMapping() supports the following prop shapes:
// Plain strings, HTML strings and URLs are considered translatable. So:
// - type: string
// - type: string: format: iri
// - type: string: format: iri-reference
// - type: string: format: uri
// - type: string: format: uri-reference
// - type: string, contentMediaType: text/html
// - type: string, contentMediaType: text/html, x-formatting-context: inline
// - type: string, contentMediaType: text/html, x-formatting-context: block
// @todo: arrays of either of those.
Canvas will make every SDC prop (or code component prop) translatable that is of one of those particular shapes.
But what if for some SDC (or even some site using an SDC), some type: string, format prop should be translatable? This is impossible to know without core's SDC subsystem's JSON Schema describing translatability of props. → Needs upstream feature
Proposed resolution
- Introduce an alter hook that allows sites/modules modifying
\Drupal\canvas\Plugin\Canvas\ComponentSource\GeneratedFieldExplicitInputUxComponentSourceBase::getExplicitInputDefinitionsAsConfigSchemaMapping()'s behavior. - However, this must be
@internaluntil bothGeneratedFieldExplicitInputUxComponentSourceBaseandComponentSourceInterfaceare public APIs. - Test-only module that verifies it works end-to-end, for both content-defined component trees and config-defined component trees
- ✅ Config translation-specific concern
The implementer of the hook must specify the appropriateform_element_classto use for the field type associated with that prop shape.
⚠️Note that Drupal core'sconfig_translationmodule has limited support for field types! It in fact only supports plain strings (TextField) and HTML strings (\Drupal\config_translation\FormElement\TextFormat— seetype: text_format).
For example, opting in atype: string, format: uriprop would require a new config translation form element class, because it uses thelinkfield type, which causes it to receive a value like this:
All solved now; existing field widgets are used automatically — see #6. Support for URLs was added with zero changes to
form_element_classstuff. 🥳
User interface changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | Screenshot 2026-04-10 at 8.57.10 AM.png | 128.64 KB | wim leers |
Comments
Comment #2
wim leersThanks @tedbow for your research into this!
Comment #3
wim leersComment #4
wim leersComment #5
wim leersTed, can you also update the IS to include your TMGMT-specific findings?
Comment #6
wim leersUpdate to account for the significant changes in the past ~2 days to https://git.drupalcode.org/project/canvas/-/merge_requests/898.
Basically, that MR was rearchitected to not use Config Translation's
Text(Field|Area), but a new customclass CanvasStaticPropSourceFieldWidget extends FormElementBasethat automatically reuses the field widget in use on the static prop source that is being translated. Which means that many of the challenges outlined here … disappear!Comment #7
wim leers#3586342: Symmetrically translatable component trees, STEP 1: introduce `ComponentInstanceInputsConfigSchemaGeneratorInterface` has clarified where what is needed.
We may need two alter hooks, or alternatively: one that supports either marking specific component props as translatable, or all props that have a specific shape (e.g. all
type: string, enum: [foo, bar]).