Warning: Array to string conversion in etracker_set_default_variables()

Created on 16 December 2022, almost 2 years ago
Updated 21 June 2023, over 1 year ago

Problem/Motivation

Warning: Array to string conversion in etracker_set_default_variables() (line 339 of modules/custom/etracker/etracker.module).

Steps to reproduce

Proposed resolution

Fix the problem

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇩🇪Germany Grevil

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    Just ran into this issue on a customer project, when trying to access a taxonomy term.

  • 🇩🇪Germany Anybody Porta Westfalica

    This is the line that causes the error:

    $variables['et_areas'][] = implode('/', $titles);
    

    Stacktrace:

    Warning: Array to string conversion in _etracker_set_default_variables() (line 339 of modules/contrib/etracker/etracker.module).
    _etracker_set_default_variables(Object) (Line: 366)
    _etracker_add_variable(Object) (Line: 208)
    etracker_page_attachments_alter(Array, NULL, NULL) (Line: 562)
    Drupal\Core\Extension\ModuleHandler->alter('page_attachments', Array) (Line: 323)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 289)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 290)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
    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: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 2) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 2, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 2, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 2, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 2, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 2, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 2, 1) (Line: 270)
    Drupal\shield\ShieldMiddleware->bypass(Object, 2, 1) (Line: 143)
    Drupal\shield\ShieldMiddleware->handle(Object, 2, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 2, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 2, 1) (Line: 49)
    Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object, 2, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 2) (Line: 166)
    Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber->makeSubrequest(Object, '/system/403', 403) (Line: 112)
    Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber->on403(Object) (Line: 109)
    Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase->onException(Object, 'kernel.exception', Object)
    call_user_func(Array, Object, 'kernel.exception', Object) (Line: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.exception') (Line: 229)
    Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object, Object, 1) (Line: 92)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191)
    Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
    Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 270)
    Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 169)
    Drupal\shield\ShieldMiddleware->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: 49)
    Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    $titles has the following content:

    array(1) {
      [0]=>
      array(2) {
        ["#markup"]=>
        string(9) "Rohstoffe"
        ["#allowed_tags"]=>
        array(12) {
          [0]=>
          string(1) "a"
          [1]=>
          string(2) "em"
          [2]=>
          string(6) "strong"
          [3]=>
          string(4) "cite"
          [4]=>
          string(10) "blockquote"
          [5]=>
          string(4) "code"
          [6]=>
          string(2) "ul"
          [7]=>
          string(2) "ol"
          [8]=>
          string(2) "li"
          [9]=>
          string(2) "dl"
          [10]=>
          string(2) "dt"
          [11]=>
          string(2) "dd"
        }
      }
    }
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    32 pass
  • @anybody opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Fixes the issue. I think rendering the render array first, would be too heavy for this functionality.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇩🇪Germany Grevil

    LGTM! Although is there ever a case where $titles is an array, but NOT a multidimensional array? From the output you provided, it seems very unlikely, that the implode will ever execute.

  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil: Yes, the typical expected case here is, that it's NOT multidimensional and just contains strings of the text. You can also see this in the existing implementation.

    The render array is the more untypical one, otherwise the error would appear on any page.

  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany Grevil

    Alright! Thanks for the explanation! 🙂

    RTBC!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    32 pass
    • Anybody committed 646f53d8 on 8.x-3.x
      Issue #3327609 by Anybody, Grevil: Warning: Array to string conversion...
  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @Grevil, merged!

  • 🇩🇪Germany Anybody Porta Westfalica
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024