Fix multilingual site's layout edit context issue with TypeError: Argument 1 passed to UrlHelper::buildQuery() must be of the type array, null given

Created on 16 December 2019, almost 5 years ago
Updated 26 January 2023, almost 2 years ago

Problem/Motivation

Given that we have Drupal core installed with the standard profile
And enabled "Language, Layout Builder, Contextual Links, Settings Tray" modules
And activated the "Use Layout Builder" and "Allow each content item to have its layout customized." on the default display mode for a selected content type
When we click on "Layout" to change the layout for a content page
Then we should not see the following error
But When we add "composer require 'drupal/layout_builder_modal:^1.0'"
And "composer require 'drupal/lb_ux:^1.0'"
And enable "Layout Builder Modal" and "Layout Builder UX" modules
Then we should see the fatal error

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Component\Utility\UrlHelper::buildQuery() must be of the type array, null given, called in /var/www/html/dev/drupal80801/web/core/modules/contextual/contextual.module on line 180 in Drupal\Component\Utility\UrlHelper::buildQuery() (line 42 of core/lib/Drupal/Component/Utility/UrlHelper.php).
Drupal\Component\Utility\UrlHelper::buildQuery(NULL) (Line: 180)
_contextual_links_to_id(Array) (Line: 139)
contextual_preprocess(Array, 'block', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('block', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 501)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 68)
__TwigTemplate_a02fc5fdb66ff3aaf13167043da76be28c60b348483b5d86e00a20c0c3be3b82->doDisplay(Array, Array) (Line: 455)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template->display(Array) (Line: 434)
Twig\Template->render(Array) (Line: 64)
twig_render_template('core/themes/stable/templates/layout/layout--onecol.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('layout__onecol', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
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: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 694)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

So when any module is changing the context .. Array or string
The system should not have a fatal error. insted a worning log could be better. to let develpers know that the context values had been changed in a wrong way.

Proposed resolution

  • Wrap with try catch and a warning logger and added the language to the message

Remaining tasks

  • Automated tests

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs review

Version

10.1

Component
Contextual 

Last updated about 2 months ago

Created by

🇯🇴Jordan Rajab Natshah Jordan

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024