TypeError: array_merge(): Argument #1 must be of type array, string given in array_merge() (line 137 of core/lib/Drupal/Core/Render/Element/RenderElement.php

This issue manifests in PHP 8.1 but does not in PHP7.4.

Upgrade to Drupal 9.4.8 and PHP 8.1

try/catch around line 137 of core/lib/Drupal/Core/Render/Element/RenderElement.php i.e:

try {
        $element['#attributes']['class'] = array_merge($element['#attributes']['class'], $class);
} catch (\TypeError $t) {}

The website encountered an unexpected error. Please try again later.
TypeError: array_merge(): Argument #1 must be of type array, string given in array_merge() (line 137 of core/lib/Drupal/Core/Render/Element/RenderElement.php).

array_merge('add_systems', Array) (Line: 137)
Drupal\Core\Render\Element\RenderElement::setAttributes(Array, Array) (Line: 102)
Drupal\Core\Render\Element\Checkbox::preRenderCheckbox(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 39)
__TwigTemplate_d6ea8ee46b5e1dadfd78d9056abf346f->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/modules/system/templates/system-config-form.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('system_config_form', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
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, 1) (Line: 81)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->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: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

CommentFileSizeAuthor
#7 array_merge_validator-3322924.patch801 bytesmanuvelasco

Issue fork drupal-3322924

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sisko created an issue. See original summary.

sisko’s picture

Issue summary: View changes
sisko’s picture

Issue summary: View changes
sisko’s picture

Title: array_merge TypeError RenderElement » TypeError: array_merge(): Argument #1 must be of type array, string given in array_merge()

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

manuvelasco’s picture

Same issue here when I try to upgrade from drupal8 to 9 and from php7.4 to 8.1

manuvelasco’s picture

StatusFileSize
new801 bytes

It worked for me.

Vishal Choudhary made their first commit to this issue’s fork.

elber’s picture

Hi please can you add the steps to reproduce the issue?

socialnicheguru’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs steps to reproduce, +Needs tests

As a bug it will require tests

Steps to reproduce should be added to the issue summary.

Also code will be committed to 11.x first so need to confirm the issue is happening there also.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ugintl’s picture

I am seeing this error on drupal 10. Should I apply this patch?

dewancodes’s picture

FIXED: I have fixed this issue by enabling following options on the following URL:

/admin/config/content/block-class/settings

Global Settings :

> Enable auto-complete
> Enable special chars
> Enable id replacement

Now I can save the block in Drupal 10.2.3 and PHP 8.2

stewest’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.