Problem/Motivation
This can be seen as a follow-up for #3391702
On that issue, it was proposed that #slots 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_scalarandElement::isRenderArraychecks 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
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3504477
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
idiaz.ronceroComment #3
idiaz.ronceroComment #5
idiaz.ronceroSubmitted MR that I have tested locally and works.
Comment #6
smustgrave commentedThank you for opening.
Lets add some test coverage for the proposed change.
Comment #7
idiaz.ronceroAdded test, executed pipeline and it passed.
Comment #8
smustgrave commentedRemoving tests tag as the test-only run shows the coverage
Summary seems clear with clear proposal that lines up with the code change.
Code change seems pretty straightforward and see no objection.
LGTM
Comment #9
berdirCan confirm that this fixes an issue I see with navigation:title the entity returns a TranslatableMarkup object.
Left one comment on the MR whether this should be expanded to MarkupInterface or even Stringable.
Comment #10
catchI think we should use MarkupInterface here.
Comment #11
berdirUpdated, also shortened the test method description, it was already over 80 characters and that made it even longer.
Comment #12
smustgrave commentedShows the test coverage
Believe this would solve a problem I see on my patterns theme were I have to pass #markup => content, in the twig file.
Change makes sense.
Comment #13
quietone commentedI didn't find any problems with this and all questions are answered.
Comment #14
quietone commentedTrying to improve the title
Comment #15
pdureau commentedHello,
Thanks for the work.
The current (11.x) logic is:
Obviously, it was not enough.
So, this MR is adding
On UI Patterns 2, they have added something a bit different:
I don't know which one is better, maybe we a mix of both would be great. I will check with them.
Comment #16
pdureau commentedI keep the issue assigned to me until I have an answer ;)
Comment #17
needs-review-queue-bot commentedThe 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.
Comment #18
geek-merlinAt least updating the title to how understand the current direction and scope.
And, let's add the Core-blessed RenderableInterface to the list.
In a time where static analysis thrives, it trumps naked render arrays.
Will look into #15. But need to grok some renderer details about #children first.
Comment #19
geek-merlinResearch note:
- There is no such class as TwigMarkup, but ui_patterns does
use Twig\Markup as TwigMarkup;Dunno if and how it hits Drupal code (did not encounter it yet), but no kittens killed putting it on our list here.
Comment #20
geek-merlin@pdureau #15:
Comment #21
geek-merlinComment #22
geek-merlinI'm needing this for my navigation breaking when an entity returns markup, so rolled it in code and attaching a snapshot for composer.
Comment #24
geek-merlinRebased. Did not investigate why this fails though.
Comment #25
pdureau commentedThanks a lot @geek-merlin.
The last pipeline run failed though. I will rebase and run the tests again. Then review your proposal.
Comment #26
pdureau commentedSame mysterious pipeline fail... investigating
Comment #27
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.
Comment #28
smustgrave commentedThink the bot was wrong on this one.
Comment #29
smustgrave commentedActually that test failure seems relevant to the issue.