Problem/Motivation

Sometimes |trim on text-icon component causes the page to break. Rendering the text first before attempting to run |trim prevents this.

Steps to reproduce

Sometimes user pages break from the text-icon component attempting to |trim on an array. It causes this white screen error:

The website encountered an unexpected error. Try again later.

TypeError: trim(): Argument #1 ($string) must be of type string, array given in trim() (line 1173 of /app/vendor/twig/twig/src/Extension/CoreExtension.php).
Twig\Extension\CoreExtension::trim() (Line: 70)
__TwigTemplate_db871b779c1ada8c7790f8431bbe582f->{closure}() (Line: 2079)
Twig\Extension\CoreExtension::captureOutput() (Line: 53)
__TwigTemplate_db871b779c1ada8c7790f8431bbe582f->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 72)
__TwigTemplate_29b742585f785ddbe49cea955293040a->{closure}() (Line: 2079)
Twig\Extension\CoreExtension::captureOutput() (Line: 69)
__TwigTemplate_29b742585f785ddbe49cea955293040a->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 170)
__TwigTemplate_8e6102bb2d458a54ba7969fe7e50bbfd->{closure}() (Line: 2079)
Twig\Extension\CoreExtension::captureOutput() (Line: 167)
__TwigTemplate_8e6102bb2d458a54ba7969fe7e50bbfd->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 301)
__TwigTemplate_5c8363be4e1d97eb56306760185b0d21->block_breadcrumb_block() (Line: 432)
Twig\Template->yieldBlock() (Line: 132)
__TwigTemplate_5c8363be4e1d97eb56306760185b0d21->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 44)
__TwigTemplate_738eb0ffd54e8b44c813bd8da29f510e->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 344)
Twig\Template->display() (Line: 359)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 490)
Drupal\Core\Render\Renderer->doRender() (Line: 503)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 586)
Drupal\Core\Template\TwigExtension->renderVar() (Line: 151)
__TwigTemplate_d9f942cd21be9601cb381b697b369888->block_banner_block() (Line: 432)
Twig\Template->yieldBlock() (Line: 80)
__TwigTemplate_d9f942cd21be9601cb381b697b369888->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 49)
__TwigTemplate_ef4177c32a83cc9cf23d1ed0e7c6ea8f->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 344)
Twig\Template->display() (Line: 359)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 490)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 90)
__TwigTemplate_16ec609d4e0e988d450b659fb529503c->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 344)
Twig\Template->display() (Line: 359)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 490)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 263)
Drupal\shield\ShieldMiddleware->bypass() (Line: 219)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

Render the text first before attempting to |trim it.

{# Prepare the text #}
      {% set rendered_text -%}
        {{- text -}}
      {%- endset %}
      {%- set text_arr = rendered_text|striptags|trim|split(' ') -%}
      {%- set text_start = text_arr|slice(0, -1)|join(' ') -%}
      {%- set text_end = text_arr|last -%}
      {%- set show_full_text = icon_group_disabled or (icon_placement == 'before' and is_external == false) -%}
      {%- set display_text = show_full_text ? text : text_start ~ ' ' -%}
      {%- set before_text = icon_placement == 'before' ? icon_markup|raw : '' -%}

Remaining tasks

User interface changes

API changes

Data model changes

Comments

nickgeorgiou created an issue. See original summary.

nickgeorgiou’s picture

Issue summary: View changes
nickgeorgiou’s picture

Issue summary: View changes
nickgeorgiou’s picture

Issue summary: View changes
fionamorrison23’s picture

Assigned: Unassigned » richardgaunt
Issue tags: +civictheme-release-1.13
richardgaunt’s picture

Assigned: richardgaunt » cb
joshua1234511’s picture

Assigned: cb » richardgaunt
Status: Active » Needs review
richardgaunt’s picture

Status: Needs review » Reviewed & tested by the community
richardgaunt’s picture

Version: 1.12.0 » 1.13.0
Assigned: richardgaunt » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.