WSOD if view block contextual filter is removed from block displayed with layout builder.

Created on 25 March 2021, over 3 years ago
Updated 28 March 2024, 7 months ago

Problem/Motivation

If you add a view block to a node layout via Layout Builder that has a contextual filter, removing the contextual filter will cause a WSOD when visiting the page. The following error message is displayed.

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: nid in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).
Drupal\layout_builder\SectionComponent->getPlugin(Array) (Line: 69)
Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent->__construct(Object, Array, ) (Line: 112)
Drupal\layout_builder\SectionComponent->toRenderArray(Array, ) (Line: 86)
Drupal\layout_builder\Section->toRenderArray(Array) (Line: 317)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Object) (Line: 276)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 351)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 293)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 100)
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. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Note:

  • I've only tested this with a node content type, but it could be happening on other entity types.
  • My test is adding the block to the default layout, so I'm not sure if adding a block to a specific node when the "Allow each content item to have its layout customized." option is used in Layout Builder has the same result.
  • This is only happening with blocks adding in Layout Builder, not the regular Block Layout regions.
  • Adding back the same contextual filter so the block can be removed seems to be a workaround.
  • I do not know if the issue happens with other types of contextual filters.

Steps to reproduce

  1. Create a view block that has a node ID contextual filter and set it to get default value from "Content ID from URL"
  2. Enable layout builder for a content type.
  3. Add the view block to the content type default layout.
  4. Add a new content type node and publish it.
  5. Remove the contextual filter from the view block.
  6. Go back to node page. You should get a WSOD with an error message.

Proposed resolution

The page should still be accessible, but a broken block message should be displayed.

Remaining tasks

  1. Confirm issue
  2. Create patch w/ tests

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Closed: cannot reproduce

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States pcate

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    Can't reproduce this in 11.x following the provided steps, but it has been a while :) I am not sure why this would have broken anything though, the views block should work just the same with or without the contextual filter?

    Anyway closing but if there is something missing from the steps and this is still occurring, please reopen.

Production build 0.71.5 2024