Score:0

Attribute Array to String Conversion Error

us flag

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.

4uk4 avatar
cn flag
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?
Rob Carr avatar
us flag
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
4uk4 avatar
cn flag
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.
Rob Carr avatar
us flag
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
Score:0
us flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.