Error: Call to a member function bundle() on null

Created on 7 July 2025, 23 days ago

Problem/Motivation

There are taxonomy pages that does not work for logged in users. They see the message

An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.

When looking at it with verbose logging, I see this:

The website encountered an unexpected error. Try again later.

Error: Call to a member function bundle() on null in editoria11y_page_attachments() (line 245 of modules/contrib/editoria11y/editoria11y.module).
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'editoria11y') (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 308)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 285)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 284)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
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(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
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: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

The person that knows how the site is set up is not available. There are multiple taxonomies on the site. Some work, while others give the aforementioned messages when an editor (including user 1) accesses them.

I'll try to identify what kind of downgrade is required for the pages to become available and then inspect the taxonomy term page to see if there is a specific setup that might make it easier to reproduce the issue.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.2

Component

Bugs

Created by

πŸ‡³πŸ‡΄Norway jonsimonsen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jonsimonsen
  • πŸ‡³πŸ‡΄Norway jonsimonsen

    It seems like the issue appeared after upgrading to 2.2.10. I'll downgrade the site to 2.2.9 for now. The affected taxonomy term pages look quite customised, so it might be difficult to create an exact way of reproducing the issue. I'll see if I can get hold of the person that set this up

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

    Thanks. This will be an easy change but it's nice to able to test.

    Finding out "what is this thing and what is its name" is startlingly complicated in Drupal, and edge cases in custom entities are common.

  • πŸ‡³πŸ‡΄Norway jonsimonsen

    but it's nice to able to test.

    It's a bit hard for me to specify how to reproduce since I don't know the project very well. I could of course test a patch on my local setup and tell you if it seems to have solved the issue there

  • πŸ‡©πŸ‡ͺGermany szeidler Berlin

    The issue is that the following line only works for entities for which the bundle key is `type`, like for nodes.

              if (($entity instanceof ContentEntityInterface) && $entity->hasLinkTemplate('canonical') && $entity->type && $entity->type->entity) {
    

    For taxonomy terms the bundle key is `vid` and therefore we get the fatal error.

    So the retrieval of the bundle entity it would need to be something like:

    $entity->get($entity->getEntityType()->getKey('bundle'))->entity;
    
  • πŸ‡©πŸ‡ͺGermany szeidler Berlin

    Here's a try for approaching the issue as a MR.

  • Pipeline finished with Success
    23 days ago
    Total: 147s
    #541053
  • πŸ‡ΊπŸ‡ΈUnited States itmaybejj

    That looks good to me. Let me do some testing against some past edge cases before tagging a release.

  • πŸ‡³πŸ‡΄Norway jonsimonsen

    Version: 2.2.11 Β» 2.2.x-dev
    Status: Active Β» Needs review
    Here's a try for approaching the issue as a MR.

    I tested this in the project where I had issues. It did result in the taxonomy page rendering correctly, but I noticed an issue on a different page that was not there before the patch was applied.

    The website encountered an unexpected error. Try again later.

    Error: Call to a member function getEntityType() on null in editoria11y_page_attachments() (line 228 of modules/contrib/editoria11y/editoria11y.module).
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 395)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 308)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks() (Line: 285)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 637)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 284)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128)
    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: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    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: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

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

    Updated MR !32. See if this works.

    $entity_type = $entity && method_exists($entity, 'bundle') ? "Taxonomy: " . $entity->bundle() : 'Taxonomy term';
    
  • πŸ‡³πŸ‡΄Norway jonsimonsen

    The updated PR does indeed seem to work on both the taxonomy term pages and other pages I've tested. I'll do some more testing later when we have this deployed to our dev instance. Is there any module functionality I should test or is it enough to verify that all the pages load? I do see that the editoria11y UI elements appear and can be interacted with, but I'm not really familiar with all the options in the module since we only use it on a few projects that I know about

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

    If it works on your project I'm satisfied. This basically removes all the new code in the PR and replaces it with a simple "If the bundle is missing a label just use this hard-coded string instead." I don't expect that to introduce regressions

  • πŸ‡ΊπŸ‡ΈUnited States itmaybejj
  • πŸ‡ΊπŸ‡ΈUnited States itmaybejj
  • πŸ‡³πŸ‡΄Norway jonsimonsen

    itmaybejj closed merge request !32

    I thought this was supposed to be merged and possibly part of the next patch version. Did you perhaps make a mistake with the MR?

  • πŸ‡©πŸ‡ͺGermany szeidler Berlin

    Setting it back to the previous state, because it seems that it hasn't been merged.

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

    I've had...less embarrassing moments. 2.2.13 tagged β†’ .

  • πŸ‡©πŸ‡ͺGermany szeidler Berlin

    Happens to the best. Thanks for the quick follow up.

Production build 0.71.5 2024