Warning:Array to string conversion in Drupal\Core\Template\AttributeArray

Created on 24 January 2024, 11 months ago
Updated 14 February 2024, 10 months ago

Problem/Motivation

We are getting the follow errors when render links that are using 'Linkit' format like below. We are using the Linkit attributes sub-module, stable9 as the sub-theme and Drupal 10.1.8.

{% set button = content['#block_content'].field_button.entity.field_link.0|view('linkit') %}

Seems to be the same issue mention here Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() πŸ’¬ Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() Fixed The patch provided does not work.


Warning: Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() (line 78 of /app/web/core/lib/Drupal/Core/Template/AttributeArray.php)
#0 /app/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Array to string...', '/app/web/core/l...', 78)
#1 [internal function]: _drupal_error_handler(2, 'Array to string...', '/app/web/core/l...', 78)
#2 /app/web/core/lib/Drupal/Core/Template/AttributeArray.php(78): implode(' ', Array)
#3 /app/web/core/lib/Drupal/Core/Template/AttributeValueBase.php(53): Drupal\Core\Template\AttributeArray->__toString()
#4 /app/web/core/lib/Drupal/Core/Template/Attribute.php(324): Drupal\Core\Template\AttributeValueBase->render()
#5 /app/web/core/lib/Drupal/Core/Template/TwigExtension.php(562): Drupal\Core\Template\Attribute->__toString()
#6 /app/vendor/twig/twig/src/Environment.php(418) : eval()'d code(45): Drupal\Core\Template\TwigExtension->renderVar(Object(Drupal\Core\Template\Attribute))ject(Drupal\Core\Template\Attribute))

Warning: Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() (line 77 of /app/web/core/lib/Drupal/Core/Template/AttributeArray.php)
#0 /app/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Array to string...', '/app/web/core/l...', 77)
#1 [internal function]: _drupal_error_handler(2, 'Array to string...', '/app/web/core/l...', 77)
#2 /app/web/core/lib/Drupal/Core/Template/AttributeArray.php(77): array_unique(Array)
#3 /app/web/core/lib/Drupal/Core/Template/AttributeValueBase.php(53): Drupal\Core\Template\AttributeArray->__toString()
#4 /app/web/core/lib/Drupal/Core/Template/Attribute.php(324): Drupal\Core\Template\AttributeValueBase->render()
#5 /app/web/core/lib/Drupal/Core/Template/TwigExtension.php(562): Drupal\Core\Template\Attribute->__toString()
#6 /app/vendor/twig/twig/src/Environment.php(418) : eval()'d code(45): Drupal\Core\Template\TwigExtension->renderVar(Object(Drupal\Core\Template\Attribute))

User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of /app/web/core/lib/Drupal/Core/Render/Element.php)
#0 /app/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(256, '"0" is an inval...', '/app/web/core/l...', 98)
#1 [internal function]: _drupal_error_handler(256, '"0" is an inval...', '/app/web/core/l...', 98)
#2 /app/web/core/lib/Drupal/Core/Render/Element.php(98): trigger_error('"0" is an inval...', 256)
#3 /app/web/core/lib/Drupal/Core/Render/Renderer.php(404): Drupal\Core\Render\Element::children(Array, true)
#4 /app/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#5 /app/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render(Array)
#6 /app/vendor/twig/twig/src/Environment.php(418) : eval()'d code(67): Drupal\Core\Template\TwigExt

πŸ’¬ Support request
Status

Fixed

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada knowak

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

Comments & Activities

  • Issue created by @knowak
  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Can we get steps to reproduce this without a custom theme
    Thanks

  • πŸ‡¨πŸ‡¦Canada knowak

    I wasn't able to reproduce this in a vanilla install.

    I found that something changed in our custom theme while we were updating to Drupal 10 that changed the behavior in how we were adding classes in our templates.

    I was able to modify our templates and stop the errors. Sorry for the false alarm and thanks for your time.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Thanks for reporting back @knowak

  • Status changed to Fixed 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024