0

I'm getting this error now on most pages within a complex 9.5.3 site running PHP8.1:

Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() (line 77 of core/lib/Drupal/Core/Template/AttributeArray.php)

The error trace isn't really helping nail this down. Using the suggestion at AttributeArray fails to implode #allowed_tags to investigate the problem attribute arrays, many of them are toolbar-tab related, but some are flagging up problems with Views embedded in the page, and some are just field-related, for example:

0 => string (6) "hidden"
1 => string (22) "contextual-toolbar-tab"
2 => string (11) "toolbar-tab"
3 => boolean false

and

#markup => string (6) "Argyll"
 #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"

and

0 => Drupal\Core\Template\AttributeString#180606 (2)
Properties (2)
  protected value -> string (29) "view-field-photo-table-column"
  protected name -> string (2) "id"

I think I've ruled out a theme issue (admin is Claro > Gin; front end is stable9 > Custom) and disabled lots of potential problem modules (admin_toolbar, devel etc), but not certain that it's a theme issue, or a rogue module. With the snippet in __toString() errors are flagged up on virtually every page.

But I'm just lost as to how to nail this down, or even where to start looking.

4
  • As I've already commented in the linked question, an array of classes, like the first toolbar output, is no problem. The issue is caused by the second output. You have to find the code putting this wrong content into an attribute array. A Scottish county might point you in the right direction. What other content comes up when you browse the page?
    – 4uk4
    Feb 11, 2023 at 14:13
  • Thanks - the majority of non-string attributes flagged up are either toolbar-related or views (value:name pair), as in examples above. The one that is clearly causing a bigger problem is the #allowed_tags array, and I've no idea how to find the cause of that. I've scanned the HTML of the erroneous pages and no DIVs jump out as being a problem
    – Rob Carr
    Feb 11, 2023 at 17:41
  • If it's not a theme it's a module. Check any code manipulating attribute variables. Start with custom code, then contrib code no longer maintained.
    – 4uk4
    Feb 11, 2023 at 19:23
  • Spent ages getting nowhere, and now the error has just 'gone away' (??). I have a feeling that it's related to caching or lazy building, but now cannot reproduce, so this feels like one of the many potential rabbit holes
    – Rob Carr
    Feb 21, 2023 at 14:08

1 Answer 1

0

Short answer - be wary of using the Shield module https://www.drupal.org/project/shield

If you look through the issue queue there are many problems where module hooks, caches or attributes can become corrupted.

As soon as the module was uninstalled, no errors were observed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.