Pass long text field into SDC component slot

Created on 14 August 2024, 4 months ago

Problem/Motivation

When passing a long text field to a component with a description slot, I use this approach:


{% embed 'component' with {
  title: node.label,
} %}
  {% block body %}
    {{ {
        '#type': 'processed_text',
        '#text': node.body.value,
        '#format': node.body.format,
    } }}
  {% endblock %}
{% endembed %}

This works fine unless the body field is empty; then an exception is thrown since node.body.value returns an empty array

TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 440 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(Array) (Line: 793)
_filter_html_escape(Array) (Line: 26)
Drupal\filter\Plugin\Filter\FilterHtmlEscape->process(Array, '') (Line: 118)
Drupal\filter\Element\ProcessedText::preRenderText(Array)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 β†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 195)
...

πŸ’¬ Support request
Status

Active

Version

10.3 ✨

Component
RenderΒ  β†’

Last updated about 8 hours ago

Created by

miiimooo Europe

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @miiimooo
  • miiimooo Europe

    To reproduce, create or edit a template (e.g. node.html.twig) to contain only this

    {{ {
      '#type': 'processed_text',
      '#text': node.body.value,
      '#format': node.body.format,
    } }}
    

    Make sure the node's body field is empty

    The website encountered an unexpected error. Try again later.

    TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 440 of core/lib/Drupal/Component/Utility/Html.php).
    Drupal\Component\Utility\Html::escape(Array) (Line: 793)
    _filter_html_escape(Array) (Line: 26)
    Drupal\filter\Plugin\Filter\FilterHtmlEscape->process(Array, '') (Line: 118)
    Drupal\filter\Element\ProcessedText::preRenderText(Array)
    call_user_func_array(Array, Array) (Line: 113)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 β†’ ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array) (Line: 475)
    Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 40)
    __TwigTemplate_cc2b7de651c1a0232f84f4093e023a1f->doDisplay(Array, Array) (Line: 360)
    Twig\Template->yield(Array) (Line: 335)
    Twig\Template->render(Array) (Line: 38)
    Twig\TemplateWrapper->render(Array) (Line: 37)
    twig_render_template('themes/custom/hrw_design/apps/drupal/templates/content/node--interactive--full.html.twig', Array, Array) (Line: 426)
    Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 491)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 53)
    Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

Production build 0.71.5 2024