Problem/Motivation

Error: Call to a member function getEntityTypeId() on null in Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->entityCacheTagsFromRoute() (line 84 of modules/contrib/notification_message/src/Cache/Context/RouteEntityUuidCacheContext.php).
Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->getContext(NULL) (Line: 123)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 317)
Drupal\Core\Render\RenderCache->createCacheID(Array) (Line: 66)
Drupal\Core\Render\RenderCache->get(Array) (Line: 109)
Drupal\Core\Render\PlaceholderingRenderCache->get(Array) (Line: 273)

Steps to reproduce

Essentially the current function assumes that a contextual filter is going to be an ID, and a proper entity slug. The way to reproduce this is to really configure any other type of contextual filter. For our particular configuration:

  • Create a new view with a page display and a path of anything/%taxonomy_term
  • Create a new contextual filter which is the Term Name. This works normally with the taxonomy term validator.

Proposed resolution

There's not any super straightforward way to solve this. If you don't use an entity slug, and you just use '%', then it will fail on getStorage('arg_0').
If you setup the contextual filter to be a taxonomy term name, then the call to getStorage('taxonomy_term')->load('name of taxonomy term') will fail.

The best we can do is first do a hasDefinition() to see if the storage actually exists and if it's an actual entity type. Then attempt to load the entity and just continue if it fails.

Remaining tasks

Review and test included patch.

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

asherry created an issue. See original summary.

asherry’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.31 KB
asherry’s picture

Issue summary: View changes
asherry’s picture

StatusFileSize
new1.8 KB

Ran into another error if the $arg variable turns out to be a proper EntityInterface object. I put in another check to see if it's a proper entity, just add it to the array, but, also check if it's an int/str to make sure it's safe to pass to entity load.

Still not sure about this solution as a whole, but, it's fixing errors for us at the moment.

heikkiy’s picture

I found this issue when installing Notification message to our side crashed a view with contextual filters in the URL.

The error in our case was this

The website encountered an unexpected error. Try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "arg_0" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Drupal\Core\Entity\EntityTypeManager->getHandler() (Line: 192)
Drupal\Core\Entity\EntityTypeManager->getStorage() (Line: 129)
Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->attachViewRouteEntities() (Line: 86)
Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->entityCacheTagsFromRoute() (Line: 60)
Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->getContext() (Line: 123)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys() (Line: 244)
Drupal\Core\Cache\VariationCache->createCacheIdFast() (Line: 175)
Drupal\Core\Cache\VariationCache->getRedirectChain() (Line: 35)
Drupal\Core\Cache\VariationCache->get() (Line: 71)
Drupal\Core\Render\RenderCache->get() (Line: 113)
Drupal\Core\Render\PlaceholderingRenderCache->get() (Line: 317)
Drupal\Core\Render\Renderer->doRender() (Line: 493)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 122)
__TwigTemplate_a80a95a6a8c5a3904dde60ae71cea77e->block_page_pre_content() (Line: 171)
Twig\Template->displayBlock() (Line: 130)
__TwigTemplate_f0b5e2f7c622ad70fb53191694409337->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 61)
__TwigTemplate_a80a95a6a8c5a3904dde60ae71cea77e->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 39)
__TwigTemplate_9e59da2f5f2329765a9dfd034cd52843->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 38)
Twig\TemplateWrapper->render() (Line: 39)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 480)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 81)
__TwigTemplate_cba7f8237d6b6745d5fea617efe7d916->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 39)
__TwigTemplate_f020d8f0b6dad9d1f81515d1f59f880c->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 38)
Twig\TemplateWrapper->render() (Line: 39)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 480)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

The patch in this issue fixed the problem. I would be willing to mark this RTBC and mark it Major or even Critical because it causes a crash. I will see if I can come up with another suggestion how to fix this.

heikkiy’s picture

I tried to improve the code a bit and made some small improvements. Here is an attached patch with following changes.

1. Added a check for $route_object being null to avoid potential errors.
2. Used instanceof instead of is_a for checking if $arg is an instance of EntityInterface.
3. Some small style changes.

Tested that the issue is still resolved.

heikkiy’s picture

I opened a MR for this for easier review and commenting.

grgcrlsn321’s picture

Status: Needs review » Reviewed & tested by the community

I'm marking this RTCB. It should be merged in because it breaks views easily using contextual filters. The patch solves the issue for handling the argument and adds validation for only passing entity types.

droath’s picture

Can someone confirm whether this issue still persists in the 2.x branch? I believe it has been addressed with the following patch: https://www.drupal.org/project/notification_message/issues/3590192.

droath’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)