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)
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | array_merge_validator-3322924.patch | 801 bytes | manuvelasco |
Issue fork drupal-3322924
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
Comment #2
sisko commentedComment #3
sisko commentedComment #4
sisko commentedComment #6
manuvelasco commentedSame issue here when I try to upgrade from drupal8 to 9 and from php7.4 to 8.1
Comment #7
manuvelasco commentedIt worked for me.
Comment #10
elberHi please can you add the steps to reproduce the issue?
Comment #11
socialnicheguru commentedComment #12
smustgrave commentedAs 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.
Comment #14
ugintl commentedI am seeing this error on drupal 10. Should I apply this patch?
Comment #15
dewancodes commentedFIXED: 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
Comment #16
stewestFYI - this is similar https://www.drupal.org/project/block_class/issues/3467450 and the patch here worked for me https://git.drupalcode.org/project/block_class/-/merge_requests/52.diff