Drupal\Component\Plugin\Exception\MissingValueContextException: Required contexts without a value: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php

Created on 28 August 2023, over 1 year ago
Updated 16 September 2024, 3 months ago

It seems like this problem has been reported multiple times over the years but I wasn't able to find a solution for it.

When editing a product page using layout builder after saving I get the message:

You have unsaved changes.

After click again on layout get a white page with the message:

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

and the log messages shows:

Drupal\Component\Plugin\Exception\MissingValueContextException: Required contexts without a value: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany elbarcino

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.

  • Issue created by @elbarcino
  • If you have URLs of the prior reports can you please list them?

  • πŸ‡©πŸ‡ͺGermany elbarcino

    There are just too many to list them all. Here are just a few. Most of them are just a variation of the same problem since are related i.e to different modules but all point to:

    Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 1xx of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).

    https://www.drupal.org/project/drupal/issues/3379768 πŸ› Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 145 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php). Active
    https://www.drupal.org/project/drupal/issues/3207875 πŸ› "Unsaved changes" message incorrectly appears on layout builder Needs work
    https://www.drupal.org/project/drupal/issues/3056135 πŸ› Viewing Layout Builder enable node fails after Workflow enabled on bundle if another node was created before enabling Fixed
    https://www.drupal.org/project/drupal/issues/3308721 πŸ’¬ Drupal\Component\Plugin\Exception\MissingValueContextException: Required contexts without a value: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/ContextHandler Closed: cannot reproduce
    https://www.drupal.org/project/page_manager/issues/3362841 ✨ Required contexts without a value: entity, view_mode Needs work
    https://www.drupal.org/project/context/issues/3081120 β†’
    https://www.drupal.org/project/drupal/issues/2952065 πŸ› Error: ContextHandler->applyContextMapping() Closed: cannot reproduce
    https://www.drupal.org/project/panels/issues/3362579 πŸ› Drupal\Component\Plugin\Exception\MissingValueContextException: Required contexts without a value: view_mode in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php). Closed: duplicate
    https://www.drupal.org/project/radix/issues/3079630 β†’
    https://www.drupal.org/project/moderation_dashboard/issues/3221316 β†’
    https://www.drupal.org/project/moderation_dashboard/issues/3060261 β†’
    https://www.drupal.org/project/drupal/issues/3207875 πŸ› "Unsaved changes" message incorrectly appears on layout builder Needs work
    https://www.drupal.org/project/drupal/issues/3225529 β†’
    https://www.drupal.org/project/drupal/issues/3065003 β†’
    https://www.drupal.org/project/drupal/issues/3045171 β†’
    https://www.drupal.org/project/layout_builder_st/issues/3222423 πŸ› Layout translation form reports unsaved changes and becomes stale Needs review

    Apparently there is a patch that just makes the message

    You have unsaved changes.

    go away but doesn't really fix the problem.

  • πŸ‡ΊπŸ‡ΈUnited States sleewok

    This is a constant battle I face. I get it in drupal 9 as well.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    I'm getting this error too, no idea where it came from, it's on one of my commerce product types and I can't disable layout builder for it through the UI. Can't edit, can't disable... Totally stuck.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Updating version

  • Can we get the stack trace please?

    Also, it would be nice to get complete and verified reproduction steps starting with the Drupal install.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    @cilefen,

    I'm not sure what caused the problem so I'm afraid I can't list the exact steps to reproduce it.
    I managed to solve the issue by directly visiting /admin/commerce/config/product-types/[PRODUCT_TYPE]/edit/display/default/layout/discard-changes and clicking "Confirm".

    Here is the stacktrace:

    #0 /var/www/XXX/core/modules/layout_builder/src/SectionComponent.php(245): Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping()
    #1 /var/www/XXX/core/modules/layout_builder/src/Event/SectionComponentBuildRenderArrayEvent.php(70): Drupal\layout_builder\SectionComponent->getPlugin()
    #2 /var/www/XXX/core/modules/layout_builder/src/SectionComponent.php(89): Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent->__construct()
    #3 /var/www/XXX/core/modules/layout_builder/src/Section.php(88): Drupal\layout_builder\SectionComponent->toRenderArray()
    #4 /var/www/XXX/core/modules/layout_builder/src/Element/LayoutBuilder.php(228): Drupal\layout_builder\Section->toRenderArray()
    #5 /var/www/XXX/core/modules/layout_builder/src/Element/LayoutBuilder.php(112): Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection()
    #6 /var/www/XXX/core/modules/layout_builder/src/Element/LayoutBuilder.php(86): Drupal\layout_builder\Element\LayoutBuilder->layout()
    #7 [internal function]: Drupal\layout_builder\Element\LayoutBuilder->preRender()
    #8 /var/www/XXX/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(111): call_user_func_array()
    #9 /var/www/XXX/core/lib/Drupal/Core/Render/Renderer.php(858): Drupal\Core\Render\Renderer->doTrustedCallback()
    #10 /var/www/XXX/core/lib/Drupal/Core/Render/Renderer.php(421): Drupal\Core\Render\Renderer->doCallback()
    #11 /var/www/XXX/core/lib/Drupal/Core/Render/Renderer.php(493): Drupal\Core\Render\Renderer->doRender()
    #12 /var/www/XXX/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender()
    #13 /var/www/XXX/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(238): Drupal\Core\Render\Renderer->render()
    #14 /var/www/XXX/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
    #15 /var/www/XXX/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(231): Drupal\Core\Render\Renderer->executeInRenderContext()
    #16 /var/www/XXX/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(128): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
    #17 /var/www/XXX/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
    #18 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    #19 /var/www/XXX/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
    #20 /var/www/XXX/vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
    #21 /var/www/XXX/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #22 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
    #23 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #24 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #25 /var/www/XXX/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle()
    #26 /var/www/XXX/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #27 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #28 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #29 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #30 /var/www/XXX/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #31 /var/www/XXX/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #32 /var/www/XXX/index.php(19): Drupal\Core\DrupalKernel->handle()
    #33 {main}
  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    This is sounding like it could potentially be related to an issue in Commerce, not Drupal core.

    πŸ› Product Variation is without context in view based listing of Products when using Layout builder for managing product display Needs review looks to be very similar to the IS, which also mentions editing a product layout.

    @AlfTheCat could you please have a look at the issue above and see it it resolves your issue?

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Hi DanielVeza, thanks I will look at the issue.

  • πŸ‡ͺπŸ‡ΈSpain gmoraleb

    Hello,

    I have the following issue:

    Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 145 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).

    I think it's a similar issue, however, it's for 9.5.11v.

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    Do you have steps to replicate this or a backtrace you could post?

    Do you use Drupal commerce?

  • πŸ‡ͺπŸ‡ΈSpain gmoraleb

    Hello Daniel,

    I don't use Drupal Commerce and it's very hard to find the steps to replicate or track because after upgrade I had problems everywhere, then I started to clean issues/warnings/deprecations and I found it.

    If you need other version information or something else, tell me.

    This is the error:

    Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 145 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).
    
    Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder->buildRegions(Array, Array, '') (Line: 179)
    Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder->build(Object) (Line: 189)
    Drupal\panels_ipe\Plugin\DisplayBuilder\InPlaceEditorDisplayBuilder->build(Object) (Line: 338)
    Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant->build() (Line: 398)
    Drupal\panelizer\PanelizerEntityViewBuilder->buildPanelized(Object, Object, 'quick_event', NULL) (Line: 355)
    Drupal\panelizer\PanelizerEntityViewBuilder->buildMultiplePanelized(Array, Array, 'quick_event', NULL) (Line: 273)
    Drupal\panelizer\PanelizerEntityViewBuilder->view(Object, 'quick_event') (Line: 32)
    Drupal\unfccc_event\Controller\UNFCCCEventQuickViewController->getEventQuickView('ajax', '633185')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    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: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    @gmoraleb it looks like your problem may be due to either the Panels or Panelizer modules. I would recommend going through the issue queue of those modules that seeing if there is an issue similar to what you're seeing.

  • πŸ‡ͺπŸ‡ΈSpain gmoraleb

    Hello @danielveza, I still have to check, I didn't have time, however, what I have seen at this moment in panels module(DisplayBuilder\StandardDisplayBuilder.php) version: 4.7.0.

    It's related with the last warning of the issue:
    Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder->buildRegions(Array, Array, '') (Line: 179)

    Because the following function has been called with (value, null)
    protected function buildRegions(array $regions, array $contexts)

    And then without checking if it's empty, try to do
    $this->contextHandler->applyContextMapping($block, $contexts);

    What it's throwing:

       * @throws \Drupal\Component\Plugin\Exception\ContextException
       *   Thrown when a context assignment was not satisfied.

    I will continue checking and I will post it.
    Thanks.

  • πŸ‡ͺπŸ‡ΈSpain gmoraleb

    Hello again,

    The problem was due to deprecated code. In our custom blocks we had to modify:

        $entity = $this->context['entity']->getContextValue();
        $url = $entity->urlInfo();
    

    By:

        $entity = $this->getContextValue('entity');
        $url = $entity->toUrl();

    And in derivative files:

    $this->derivatives[$delta]['context']['entity'] =

    By:

    $this->derivatives[$delta]['context_definitions']['entity'] =

    And those changes fixed our problem.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    This happened to me again on a new project. This time, visiting the "Discard changes" URL did not solve the problem.

    The problem occurred when I created a Flag, and checked the option to list the link to the flag as a field on all my Commerce Product Variations. This instantly broke all of them, and the only way to get Layout builder back in action was to undo that flag setting.

    Layout builder is becoming a Liability builder with this issue, I get it on every project at least once. This time it's more problematic as it can't be undone.

  • Hello @AlfTheCat.
    I have the same problem - https://www.drupal.org/project/drupal/issues/3383732#comment-15410980 πŸ› Drupal\Component\Plugin\Exception\MissingValueContextException: Required contexts without a value: entity in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 150 of web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php Postponed: needs info .
    I get this error periodically when I edit blocks in the layout builder and one of the blocks is not updated when i click on the "Update" button.
    "Discard changes" URL did not solve the problem.
    Drupal version 10.2.6.

    Did you manage to solve this issue?

  • πŸ‡ΊπŸ‡ΈUnited States MegaphoneJon

    Here's a backtrace of this problem occurring when I try to load a particular webform. Given the block repository reference, I suspect I'm having the same (or related) issue to @Alex_web.

    Commenting out the first foreach loop in Drupal\block\BlockRepository::getVisibleBlocksPerRegion() bypasses this issue.

    Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping (/home/jon/local/mysite/web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php:150)
    Drupal\block\BlockAccessControlHandler->checkAccess (/home/jon/local/mysite/web/core/modules/block/src/BlockAccessControlHandler.php:92)
    Drupal\Core\Entity\EntityAccessControlHandler->access (/home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php:105)
    Drupal\Core\Entity\EntityBase->access (/home/jon/local/mysite/web/core/lib/Drupal/Core/Entity/EntityBase.php:314)
    Drupal\block\BlockRepository->getVisibleBlocksPerRegion (/home/jon/local/mysite/web/core/modules/block/src/BlockRepository.php:63)
    Drupal\block\Plugin\DisplayVariant\BlockPageVariant->build (/home/jon/local/mysite/web/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php:137)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare (/home/jon/local/mysite/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php:274)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse (/home/jon/local/mysite/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php:132)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray (/home/jon/local/mysite/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php:90)
    call_user_func:{/home/jon/local/mysite/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142} (/home/jon/local/mysite/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch (/home/jon/local/mysite/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw (/home/jon/local/mysite/web/vendor/symfony/http-kernel/HttpKernel.php:174)
    Symfony\Component\HttpKernel\HttpKernel->handle (/home/jon/local/mysite/web/vendor/symfony/http-kernel/HttpKernel.php:81)
    Drupal\Core\StackMiddleware\Session->handle (/home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/Session.php:58)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle (/home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:48)
    Drupal\page_cache\StackMiddleware\PageCache->pass (/home/jon/local/mysite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106)
    Drupal\page_cache\StackMiddleware\PageCache->handle (/home/jon/local/mysite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85)
    Drupal\ban\BanMiddleware->handle (/home/jon/local/mysite/web/core/modules/ban/src/BanMiddleware.php:50)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle (/home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:48)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle (/home/jon/local/mysite/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:51)
    Stack\StackedHttpKernel->handle (/home/jon/local/mysite/web/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23)
    Drupal\Core\DrupalKernel->handle (/home/jon/local/mysite/web/core/lib/Drupal/Core/DrupalKernel.php:718)
    {main} (/home/jon/local/mysite/web/index.php:19)
    
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    @Alex_web no solution yet, other than to use the "discard changes" URL.

  • πŸ‡ΊπŸ‡ΈUnited States gslexie

    There are likely a number of pathways to reach the same error message. But I've figured out how I did it with my own code:

    I programmatically created a custom block plugin. My content team has created a lot of nodes with layout overrides, and my custom block has been included on a number of those nodes. I am now refactoring the block, which involves adding a required context definition (layout_builder.entity).

    Layout Builder serializes the entire block config and writes it into the database at the time the block is created, and that includes the block's context mapping. Previously created blocks are missing the necessary mapping and *sometimes* create this error message. Specifically, it crashes while editing a layout override but works as I intended while viewing a node at its entity.node.canonical route. Somehow newly created blocks are acquiring the necessary mapping automatically and they work in both cases.

    I solved the issue by defining a default mapping in my block plugin as described at the end of this stackoverflow thread: https://drupal.stackexchange.com/questions/283983/how-to-create-a-custom...

      public function defaultConfiguration(): array {
        return [
            'context_mapping' => [
              'entity' => 'layout_builder.entity',
            ],
          ] + parent::defaultConfiguration();
      }
    

    It's not yet clear to me whether I should be needing to define that mapping explicitly, seeing as Layout Builder is able to provide it automatically in certain situations. But it has resolved my issues, and I wonder if some contrib modules that contain custom block plugins may have the same problem.

  • πŸ‡§πŸ‡ΎBelarus rahunak

    Hey guys, what's new with the solution?
    Has anyone found the fix?

  • πŸ‡ΊπŸ‡ΈUnited States cybercoda

    Any solution for this. Having same issue when trying to migrate D8 to D9. Note that I don't use commerce module.

  • First commit to issue fork.
Production build 0.71.5 2024