- Issue created by @idiaz.roncero
- Merge request !111143504477 - Make TranslatableMarkup slot-ready by wrapping it β (Open) created by idiaz.roncero
- πͺπΈSpain idiaz.roncero Madrid
Submitted MR that I have tested locally and works.
- πΊπΈUnited States smustgrave
Thank you for opening.
Lets add some test coverage for the proposed change.
- πͺπΈSpain idiaz.roncero Madrid
Added test, executed pipeline and it passed.
- πΊπΈUnited States smustgrave
Removing tests tag as the test-only run shows the coverage
1) Drupal\KernelTests\Components\ComponentRenderTest::testRender Drupal\Core\Render\Component\Exception\InvalidComponentDataException: Unable to render component "sdc_test:my-banner". A render array or a scalar is expected for the slot "banner_body" when using the render element with the "#slots" property
Summary seems clear with clear proposal that lines up with the code change.
Code change seems pretty straightforward and see no objection.
LGTM
- π¨πSwitzerland berdir Switzerland
Can 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.
- π¨πSwitzerland berdir Switzerland
Updated, also shortened the test method description, it was already over 80 characters and that made it even longer.
- πΊπΈUnited States smustgrave
1) Drupal\KernelTests\Components\ComponentRenderTest::testRender Drupal\Core\Render\Component\Exception\InvalidComponentDataException: Unable to render component "sdc_test:my-banner". A render array or a scalar is expected for the slot "banner_body" when using the render element with the "#slots" property /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Element/ComponentElement.php:118 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Element/ComponentElement.php:65 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php:107 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Renderer.php:830 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Renderer.php:387 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Renderer.php:459 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Renderer.php:203 /builds/issue/drupal-3504477/core/tests/Drupal/KernelTests/Components/ComponentKernelTestBase.php:95 /builds/issue/drupal-3504477/core/lib/Drupal/Core/Render/Renderer.php:593 /builds/issue/drupal-3504477/core/tests/Drupal/KernelTests/Components/ComponentKernelTestBase.php:95 /builds/issue/drupal-3504477/core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php:313 /builds/issue/drupal-3504477/core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php:45 ERRORS!
Shows 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.
- Status changed to RTBC
3 months ago 6:32am 26 April 2025 - π³πΏNew Zealand quietone
I didn't find any problems with this and all questions are answered.
- π«π·France pdureau Paris
Hello,
Thanks for the work.
The current (11.x) logic is:
if (\is_scalar($slot_value)) { $slot_value = [ "#plain_text" => (string) $slot_value, ]; }
Obviously, it was not enough.
So, this MR is adding
if ($slot_value instanceof MarkupInterface) { $slot_value = [ "#markup" => $slot_value, ]; }
On UI Patterns 2, they have added something a bit different:
if (($value instanceof TwigMarkup) || ($value instanceof MarkupInterface)) { return ['#children' => $value]; } if ($value instanceof \Stringable) { return [ '#plain_text' => (string) $value, ]; }
I don't know which one is better, maybe we a mix of both would be great. I will check with them.
- π«π·France pdureau Paris
I keep the issue assigned to me until I have an answer ;)
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.