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

Issue fork drupal-3101231

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

RajabNatshah created an issue. See original summary.

rajab natshah’s picture

StatusFileSize
new916 bytes
rajab natshah’s picture

Component: layout_builder.module » contextual.module
rajab natshah’s picture

Assigned: rajab natshah » Unassigned
Status: Active » Needs review
Issue tags: +Context, +Layout Builder, +multilingual
rajab natshah’s picture

Title: Fix multilingual site's layout edit context issue with TypeError: Argument 1 passed to Drupal\Component\Utility\UrlHelper::buildQuery() must be of the type array, null given » Fix multilingual site's layout edit context issue with TypeError: Argument 1 passed to UrlHelper::buildQuery() must be of the type array, null given
rajab natshah’s picture

StatusFileSize
new888 bytes

The last submitted patch, 2: 3101231-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 6: 3101231-6.patch, failed testing. View results

rajab natshah’s picture

StatusFileSize
new890 bytes
rajab natshah’s picture

Status: Needs work » Needs review
rajab natshah’s picture

Status: Needs review » Needs work

The last submitted patch, 9: 3101231-9.patch, failed testing. View results

rajab natshah’s picture

StatusFileSize
new911 bytes
rajab natshah’s picture

Status: Needs work » Needs review
rajab natshah’s picture

Status: Needs review » Needs work

The last submitted patch, 13: 3101231-13.patch, failed testing. View results

davidferlay’s picture

From https://www.drupal.org/project/layout_builder_modal/issues/3101572#comme...

Had the issue only when I updated Drupal core to 8.8.0
for the rout_parameters value

  1. Tested to send an empty string '' it worked but the automated test failed
  2. Tested to send NULL it worked but the automated test failed
  3. Tested to send an empty array UrlHelper::buildQuery([]) it worked but the automated test failed

In my opinion it could be handled from Drupal core.
It could be that the automated tests should be changed

Remaining todo :

  • Fix the automated tests
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB
new880 bytes

Please try this patch - it will show which group fails and then we could find why params is not initialized

The error in related issue shows that some contextual link wrongly build

+++ b/core/modules/contextual/contextual.module
@@ -177,7 +177,7 @@ function _contextual_links_to_id($contextual_links) {
-    $route_parameters = UrlHelper::buildQuery($args['route_parameters']);
+    $route_parameters = ((isset($args['rout_parameters']) && is_array($args['rout_parameters'])) ? UrlHelper::buildQuery($args['route_parameters']) : UrlHelper::buildQuery([]));

there's typo `s/rout/route`

rajab natshah’s picture

StatusFileSize
new1.81 KB

Thank you Andrey for clearing

  • Fixed the typo ( embarrassing )
  • Wrapped with try catch and a warning logger and added the language to the message
    try {
      $route_parameters = ((isset($args['route_parameters']) && is_array($args['route_parameters'])) ? UrlHelper::buildQuery($args['route_parameters']) : UrlHelper::buildQuery([]));
      $args += ['metadata' => []];
      // Add the current URL language to metadata so a different ID will be
      // computed when URLs vary by language. This allows to store different
      // language-aware contextual links on the client side.
      $args['metadata'] += ['langcode' => $langcode];
      $metadata = UrlHelper::buildQuery($args['metadata']);
      $ids[] = "{$group}:{$route_parameters}:{$metadata}";
    }
    catch (ClientException $e) {
      \Drupal::logger('contextual')->warning('Contextual link for group @group has broken metadata for language @langcode code', ['@group' => $group, '@langcode' => $langcode]);
    }
davidferlay’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #19 tested and working @RajabNatshah :)

I'm glad the issue is moving forward

longwave’s picture

@davidferlay If the patch is working for you, what is the exact warning message that is logged? That will help us fix the problem at the source.

davidferlay’s picture

Hi @longwave,

The initial error I was encountering is described in detail here : https://www.drupal.org/project/layout_builder_modal/issues/3101572

Hope it helps

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks for filing this bug report and for fixing it. Bug fixing is very valuable. However in order to commit a bug fix we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:

  1. https://www.drupal.org/docs/8/testing
  2. https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.7.x

Also some steps to reproduce the problem would be great so we can see why the problem is happening and perhaps address the root cause rather than the symptoms.

rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nwom’s picture

#19 worked great and fixed my WSOD when attempting to edit the layout via Layout Builder on any content type or node. This was able to be successfully applied against 9.06.

Edit: Also works on 9.07

Greenman77’s picture

I am now on Drupal 8.9.7 as the patch is to core I was unwilling to apply however disabling my layout modal at least allows to load the layout page.

Thanks @davidferlay for the hint #17 proceeding without layout modal module.

rajab natshah’s picture

Version: 8.9.x-dev » 9.1.x-dev
rajab natshah’s picture

Version: 9.1.x-dev » 9.3.x-dev
lendude’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce, +Bug Smash Initiative

Per #23 : "Also some steps to reproduce the problem would be great so we can see why the problem is happening and perhaps address the root cause rather than the symptoms."

We will really need some steps to reproduce this or a failing automated test that demonstrates the problem otherwise we have no idea if we are fixing a problem or just hiding a problem.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aspilicious’s picture

The previous patch deleted to many contextual links.
I wasn't able to translate the inline blocks anymore with the core sync patch.
My version works but probably isn't perfect.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

qusai taha’s picture

StatusFileSize
new1.97 KB

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

rajab natshah’s picture

Status: Postponed (maintainer needs more info) » Needs review

The last submitted patch, 34: layout-builder-translation-issue-3101231-34.patch, failed testing. View results

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

webfaqtory’s picture

StatusFileSize
new1.71 KB

Patch for D10. Tested on D10.1.2

webfaqtory’s picture

I have the patch for "Allow synced Layout override Translations: translating labels and inline blocks" 2946333-d10-307.patch installed and there was no configure block icon when hovering over the block when using my 3101231-D10.patch.

I have fixed the missing $args['route_parameters'] (they are availabe in $contextual_links['layout_builder_block_translation'] or $contextual_links['layout_builder_inline_block_translation']) and everything now works.

Not sure that this is the best place for this fix so have also posted in the "Allow synced Layout override Translations: translating labels and inline blocks" issue queue. But it is here if anyone else has this problem.

marcellinostroosnijder’s picture

StatusFileSize
new2.44 KB

Credits to Gauravvvv, but added the patch to the wrong issue:

I have fixed the cc failure, added use statement for ClientException and updated elseif condition, Attached patch and interdiff for same

michaelsoetaert’s picture

StatusFileSize
new2.42 KB

Just as comment #36, I use a patch from Admin toolbar and contextual links should always be rendered in the admin language (if set) and just encountered this issue. I've rerolled the patch from comment #44 to apply on the (latest) MR #4604.

joseph.olstad’s picture

patch #44 works on D10.4.6 however patch #45 fails to apply.
patch #44 works on D11.1.6 however patch #45 fails to apply.

Recommend continuing with patch #44 and ignoring patch #45

Patch #44 resolves the bug, prevents WSOD when using layout_builder on a node page in the other language.

waropd’s picture

StatusFileSize
new2.26 KB

#44 & #45 wouldn't apply on 11.1.8

patriciacb made their first commit to this issue’s fork.

patriciacb’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Thanks for reviving this issue. Unfortunately still need to add clear steps to reproduce to the summary. Also will need test coverage.

patriciacb’s picture

I have added patch #47, which was working fine.

rajab natshah’s picture

Version: 11.x-dev » main

bbu23 made their first commit to this issue’s fork.

bbu23’s picture

I'm in a bit of a hurry, but I updated the MR which mirrors the patch #47 to remove the unknown Client Exception, and adjust the route params fallback to an empty array. Tested with 11.3+ and layout_builder_st + layout_builder_modal. Enabling layout_builder_modal has caused the issue for me.