'Required contexts without a value: node' when editing menu

Created on 19 December 2016, over 7 years ago
Updated 24 March 2024, 3 months ago

I'm running into this error whenever trying to edit a menu item

Drupal\Component\Plugin\Exception\ContextException: Required contexts without a value: node. in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 112 of /var/www/aaep.org/http/web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).
When I add new menu items to replace the ones that weren't working using the same links and titles it works, but then another random menu link breaks.

Here is the full error message

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

Drupal\Component\Plugin\Exception\ContextException: Required contexts without a value: node. in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 112 of core/lib/Drupal/Core/Plugin/Context/ContextHandler.php). Drupal\page_manager\Entity\PageAccess->checkAccess(Object, 'view', Object) (Line: 93) Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'view', Object, 1) (Line: 340) Drupal\Core\Entity\Entity->access('view', Object, 1) (Line: 61) Drupal\Core\Entity\EntityAccessCheck->access(Object, Object, Object) (Line: 29) Drupal\page_manager\Entity\PageAccessCheck->access(Object, Object, Object) call_user_func_array(Array, Array) (Line: 163) Drupal\Core\Access\AccessManager->performCheck('page_manager.page_access_check', Object) (Line: 139) Drupal\Core\Access\AccessManager->check(Object, Object, NULL, 1) (Line: 92) Drupal\Core\Access\AccessManager->checkNamedRoute('entity.node.canonical', Array, Object, 1) (Line: 67) Drupal\menu_link_content\MenuLinkContentAccessControlHandler->checkAccess(Object, 'update', Object) (Line: 93) Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'update', Object, 1) (Line: 593) Drupal\Core\Entity\ContentEntityBase->access('update', Object, 1) (Line: 61) Drupal\Core\Entity\EntityAccessCheck->access(Object, Object, Object) call_user_func_array(Array, Array) (Line: 163) Drupal\Core\Access\AccessManager->performCheck('access_check.entity', Object) (Line: 139) Drupal\Core\Access\AccessManager->check(Object, Object, Object, 1) (Line: 112) Drupal\Core\Access\AccessManager->checkRequest(Object, Object, 1) (Line: 102) Drupal\Core\Routing\AccessAwareRouter->checkAccess(Object) (Line: 87) Drupal\Core\Routing\AccessAwareRouter->matchRequest(Object) (Line: 154) Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object, 'kernel.request', Object) (Line: 111) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', Object) (Line: 125) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64) 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: 99) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

According to someone on stack overflow as seen here http://drupal.stackexchange.com/questions/223365/required-contexts-witho...

According to that backtrace, it looks like you have a link to a page_manager page and there you probably have access conditions to limit access to a certain node type or so.

That's a page_manager bug that you need to report there. The exception can be fixed pretty easily, but it is also possible that you then simply don't have access to edit that menu link, as page_manager things that access is denied as the node type isn't matching as there is no node. That might be a bit harder to fix.

Part of that might be because the core permission to see and edit all menu links (link to any page or so) isn't fully working either.

🐛 Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

🇺🇸United States matthew.h

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update 11 months ago
    88 pass
  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    Re-roll of #12.

    This is working for me.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    79 pass, 14 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 5.7
    last update 9 months ago
    88 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update 9 months ago
    88 pass
  • 🇺🇸United States jghyde

    #12 works with D9.3.22. It also solved my page_manager problem related to contexts and controllers matching.

  • 🇺🇸United States jghyde

    When upgrading from 9.1.2 to 9.3.22 received this error caused by page_manager when attempting drush updb.

    PHP Fatal error: Declaration of Drupal\page_manager\Entity\Page::getContexts() must be compatible with Drupal\page_manager\PageInterface::getContexts
    

    Applying this patch at #17 solved the issue.

    (I am in Drupal upgrade prison with a large site. Hopefully this will get indexed into Google and help any others in same boat).

  • 🇩🇪Germany Hydra

    We first used this patch as well and it seemed to fix our problem. But manipulating the request this way will lead to a loss of information on the route in some circumstances which will result in other, unfixable issues.

    For us the solution was to use page managers PAGE_CONTEXT Event to add our missing context which looked kinda like this for our missing group context:

      public function onPageManagerPageContext(PageManagerContextEvent $event) {
        $page = $event->getPage();
        foreach ($page->getContexts() as $context) {
          if (!$context->hasContextValue()) {
            $context_definition = $context->getContextDefinition();
            if ($context_definition->getDataType() == 'entity:group') {
              // Tell page_manager about our context value.
              $page->addContext('group', new Context($context_definition, $this->getGroupFromRoute()));
            }
          }
        }
      }
    
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    @Hydra #20:
    > But manipulating the request this way will lead to a loss of information on the route in some circumstances which will result in other, unfixable issues.

    This is a bit foggy and not productive in getting this further. Can you elaborate?

  • Status changed to Needs work 5 months ago
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Patch #17 applies cleanly on current core 10.2.2 and fixes the issue for me.

    Code looks good and reasonable, and i can not see or guess what the #20 objection may mean.
    (#17 manipulates a separate request and pushes / pops it onto the stack.)

    This fix MAY be affected by the related long-standing core issue though.
    So if people experience new problems with this patch, imho they should try applying the other too and report back.

    Setting NW for an automated test, which might look like this:
    - Create a page with a context, use the context to control page access
    - Create a $url for that page and call $url->access()

  • 🇩🇪Germany Hydra

    @geek-merlin - it's a while ago I faced this issue. But as far as I can remember (and my git history tells me) we had a local task (tab) added to the group tasks which pointed to a page_manager page route. That page of course has the group context configured and used a custom condition plugin to determine the access. That condition used the group context to check for some information related to the group in order to grant or deny access. In combination with this patch, this resulted in an error on the local task access check level - kinda related to what berdir described what could happen to menu links in #5
    Removing the patch and adding the event subscriber with the provided code in #20 solved that for us and solved the original issue we used the patch for in the first place.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 8.1 & MySQL 5.7
    last update 3 months ago
    78 pass, 4 fail
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    #23: Thanks. Nothing that can be reproduced though.

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Looked a bit deeper into this and found that the logic of #17 is not enough in many cases.

    Rolled a MR that is way more robust and fixes the issue for me. Still needs tests though.

  • Pipeline finished with Failed
    3 months ago
    Total: 216s
    #127868
  • Pipeline finished with Failed
    2 months ago
    Total: 277s
    #142799
Production build 0.69.0 2024