Say i have a view page at /my_url/%group/MY_VIEW, and i have group context in my page for a block, which appears at /my_url/*/*. Now if we go to correct url ie., /my_url/%group/MY_VIEW , then everything works fine. But when i go to /my_url/%group/NOT_MY_VIEW, then the GroupCacheContext gives the exception that

Error: Call to a member function bundle() on null in modules/contrib/group/src/Cache/Context/GroupCacheContext.php

I have traced the problem to this function, getGroupFromRoute() from trait: GroupRouteContextTrait

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sumanthkumarc created an issue. See original summary.

kducharm’s picture

Status: Active » Needs review
FileSize
750 bytes

I came across a similar issue of:

Error: Call to a member function bundle() on null in Drupal\group\Cache\Context\GroupCacheContext->getContext() (line 40 of modules/contrib/group/src/Cache/Context/GroupCacheContext.php).
Drupal\group\Cache\Context\GroupCacheContext->getContext(NULL) (Line: 119)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 209)
Drupal\views\Plugin\views\cache\CachePluginBase->generateResultsKey() (Line: 132)
Drupal\views\Plugin\views\cache\CachePluginBase->cacheGet('results') (Line: 1416)
Drupal\views\ViewExecutable->execute(NULL) (Line: 1451)
Drupal\views\ViewExecutable->render() (Line: 183)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1627)
Drupal\views\ViewExecutable->executeDisplay('page_1', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
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: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 40)
Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 84)
Drupal\shield\ShieldMiddleware->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: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

when using a relationship on a view to a "Content Group Content". See if the attached patched resolves the issue there, this is similar to what is done in the GroupMembershipCacheContext getContext() function - to check if it has a group before trying to call methods on it.

Jaypan’s picture

Status: Needs review » Reviewed & tested by the community

Patch works for me. Thanks!

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Closed (outdated)

GroupCacheContext is deprecated and will be removed in 8.1.0. Please reopen a new issue in case this still occurs with RouteGroupCacheContext. Thanks for the patch though and I'm sorry it took me this long to get around to reviewing it.