Problem/Motivation
This can be seen as a follow-up for #3391702
On that issue, it was proposed that #slot
s were made more resilient and forgiving by accepting non-scalar values.
Another common Drupalism we might be facing on slots are translated strings, which
- Can include simple inline HTML tags, like
<br>
or<em>
- Will take the shape of a
TranslatableMarkup
, which will fail both theis_scalar
andElement::isRenderArray
checks and, as such, will be rejected witj an exception
Steps to reproduce
Try to feed a translated string (with or without HTML) to a slot:
return [
'#type' => 'component',
'#component' => 'theme:icon_message',
'#props' => [
'icon' => $this->options['icon'],
],
'#slots' => [
'message' => $this->t('No @type were found.<br> Please try again later.', ['@type' => $this->options['content_type']]),
]
];
A 'Unable to render component "%s". A render array or a scalar is expected for the slot "%s" when using the render element with the "#slots" property',
will be thrown.
Proposed resolution
As we did with scalars, wrap the translatable markup in order to make it pass the checks and render.
Remaining tasks
Propose a MR
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None