- Issue created by @agentrickard
Breadcrumbs text may be a string or a TranslatableMarkup object, depending on its source. Routes provide TranslatableMarkup by default but nodes provides strings.
Schema need to reflect that or the theme function signature needs to change,
We have several options here. Note the following:
This schema will fix the problem but seems inadequate:
text:
title: Text
type:
- string
- object
This actually fails, since TranslatableMarkup isn't registered with the validator the way that Attributes are:
text:
title: Text
type:
- string
- Drupal\Core\StringTranslation\TranslatableMarkup
Throws:
Drupal\Core\Render\Component\Exception\InvalidComponentException: [props.properties.items.items.properties.text.type] Does not have a value in the enumeration ["array","boolean","integer","null","number","object","string"]/n[props.properties.items.items.properties.text.type[1]] Does not have a value in the enumeration ["array","boolean","integer","null","number","object","string"]/n[props.properties.items.items.properties.text.type] Failed to match at least one schema/n[props.properties.items.items] Object value found, but an array is required/n[props.properties.items.items] Failed to match at least one schema in Drupal\Core\Theme\Component\ComponentValidator->validateDefinition() (line 121 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
So perhaps we should register TranslatableMarkup as a valid class here.
We currently allow render arrays to be passed with special validation. Perhaps items designated as strings should also pass validation if they send TranslatableMarkup to the component.
Reference: ComponentValidator::validateProps
// Dismiss type errors if the prop received a render array.
$errors = array_filter(
$validator->getErrors(),
function (array $error) use ($context): bool {
if (($error['constraint'] ?? '') !== 'type') {
return TRUE;
}
return !Element::isRenderArray($context[$error['property']] ?? NULL);
}
);
Perhaps the breadcrum function should pre-translate and always pass a string here.
Decide on the solution
None
Uncertain
None?
Active
11.0 π₯