Problem/Motivation

We are seeing this notice when we are on 404 page not found:

Notice: Array to string conversion in Drupal\lupus_ce_renderer\CustomElementsRenderer->getBreadcrumbs() (Zeile 213 in /app/web/modules/contrib/lupus_ce_renderer/src/CustomElementsRenderer.php)

#0 /app/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Array to string...', '/app/web/module...', 213, Array)
#1 /app/web/modules/contrib/lupus_ce_renderer/src/CustomElementsRenderer.php(213): _drupal_error_handler(8, 'Array to string...', '/app/web/module...', 213, Array)
#2 /app/web/modules/contrib/lupus_ce_renderer/src/CustomElementsRenderer.php(147): Drupal\lupus_ce_renderer\CustomElementsRenderer->getBreadcrumbs(Object(Drupal\Core\Render\BubbleableMetadata))

Core link element looks like this (and doesn't have `getText()` method):

/app/web/core/lib/Drupal/Core/Link.php:87:
array (size=2)
/app/web/modules/contrib/lupus_ce_renderer/src/CustomElementsRenderer.php:209:
object(Drupal\Core\Link)[8605]
  protected 'linkGenerator' => null
  protected 'text' => 
    array (size=2)
      '#markup' => string 'TaxonomyTerm' (length=12)
      '#allowed_tags' => 
        array (size=12)
          0 => string 'a' (length=1)
          1 => string 'em' (length=2)
          2 => string 'strong' (length=6)
          3 => string 'cite' (length=4)
          4 => string 'blockquote' (length=10)
          5 => string 'code' (length=4)
          6 => string 'ul' (length=2)
          7 => string 'ol' (length=2)
          8 => string 'li' (length=2)
          9 => string 'dl' (length=2)
          10 => string 'dt' (length=2)
          11 => string 'dd' (length=2)
  protected 'url' => 
    object(Drupal\Core\Url)[8502]
      protected 'urlGenerator' => null
      protected 'urlAssembler' => null
      protected 'accessManager' => null
      protected 'routeName' => string 'entity.taxonomy_term.canonical' (length=30)
      protected 'routeParameters' => 
        array (size=1)
          'taxonomy_term' => string '6' (length=1)
      protected 'options' => 
        array (size=0)
          empty
      protected 'external' => boolean false
      protected 'unrouted' => boolean false
      protected 'uri' => null
      protected 'internalPath' => null
      protected '_serviceIds' => 
        array (size=0)
          empty
      protected '_entityStorages' => 
        array (size=0)
          empty

The php notice is then produced when getText method is called and converted to string.

        $breadcrumbs[] = [
          'frontpage' => $crumb->getUrl()->getRouteName() == '<front>',
          'url' => $crumb->getUrl()->toString(),
          'label' => (string)  $crumb->getText(),
        ];

Steps to reproduce

Try accessing a nonexistent path that is nested under taxonomy term and breadrumb should be build for that taxonomy term as well.

yourdomain.com/term/nonexistingpath

Proposed resolution

`getText()` method (of Drupal\Core\Link) returns array instead of string (for taxonomy term). I propose a custom check for the type of value that is returned and then try to get correct value out of array.

Comments

useernamee created an issue. See original summary.

useernamee’s picture

I attaching patch with described solution in place.

useernamee’s picture

Issue summary: View changes
useernamee’s picture

Status: Active » Needs review
fago’s picture

Status: Needs review » Needs work

Seems reasonable. However we don't want to have markup in a breadcrumb label, thus let's run strip_tags() over the #markup string if there is one.

useernamee’s picture

Status: Needs work » Needs review
StatusFileSize
new934 bytes

I've added strip_tags function around text.

useernamee’s picture

We actually need patch of alpha9 version of this module so I'm attaching that one as well.

mostepaniukvm’s picture

Status: Needs review » Fixed

Thanks,
Commited in dev branch

Status: Fixed » Closed (fixed)

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