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

Created on 12 September 2024, 3 months ago

Problem/Motivation

We have a nextjs front end through next-drupal and it's making this request to translate the homepage path:
/router/translate-path?path=%2F%2Fhome

That was producing a 500 error:

Error: Call to a member function isMultilingual() on null in Drupal\decoupled_router\EventSubscriber\RedirectPathTranslatorSubscriber->onPathTranslation() (line 53 of web/modules/contrib/decoupled_router/src/EventSubscriber/RedirectPathTranslatorSubscriber.php).

With this stack trace in Drupal:

#0 [internal function]: Drupal\decoupled_router\EventSubscriber\RedirectPathTranslatorSubscriber->onPathTranslation()
#1 web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#2 web/modules/contrib/decoupled_router/src/Controller/PathTranslator.php(78): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#3 [internal function]: Drupal\decoupled_router\Controller\PathTranslator->translate()
#4 web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#5 web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#6 web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#7 web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#8 vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#10 web/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(68): Symfony\Component\HttpKernel\HttpKernel->handle()
#11 web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle()
#12 web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#13 web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#14 vendor/asm89/stack-cors/src/Cors.php(53): Drupal\Core\StackMiddleware\ContentLength->handle()
#15 web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle()
#16 web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#17 web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#18 web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#19 web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#20 web/index.php(19): Drupal\Core\DrupalKernel->handle()
#21 {main}

Steps to reproduce

I'm a bit new to this website, so I'm not sure what's all involved in reproducing this. It's using tmgmt and content_translation and this is a page with a translation, though in this case we're looking at the source page.

Proposed resolution

I think RouterPathTranslatorSubscriber is missing a couple of arguments to the constructor that's preventing languageManager from getting set. I've attached a patch.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Peter Haight

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

Comments & Activities

  • Issue created by @Peter Haight
  • πŸ‡ΊπŸ‡ΈUnited States Peter Haight
  • πŸ‡ΈπŸ‡ͺSweden thomjjames Sweden

    Hi,

    Also getting this during a Drupal 9 -> 10 upgrade process. I tried the patch but I still get 404s on the frontend and these log errors:

    ArgumentCountError: Too few arguments to function Drupal\decoupled_router\EventSubscriber\RouterPathTranslatorSubscriber::__construct(), 6 passed in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 and exactly 8 expected in Drupal\decoupled_router\EventSubscriber\RouterPathTranslatorSubscriber->__construct() (line 92 of /var/www/html/web/modules/contrib/decoupled_router/src/EventSubscriber/RouterPathTranslatorSubscriber.php).

    The original Error: Call to a member function isMultilingual() is gone however :)

    I'm using next-drupal as well so will check the issue queue there too, not had much time to look into this yet.

    Thanks
    Tom

  • πŸ‡ΈπŸ‡ͺSweden thomjjames Sweden

    Hello again,

    Ok turned out a pretty simple fix :)

    The patches in the next-drupal docs (https://next-drupal.org/learn/quick-start/apply-patches) stopped applying so I assumed they were fixed and removed both, turns out only the subrequest patch is merged ( https://www.drupal.org/project/subrequests/issues/3049395 πŸ› Page Cache causes different subrequests to return the same responses Fixed ) not the decoupled router patch ( https://www.drupal.org/project/decoupled_router/issues/3111456 πŸ› Unable to resolve path on node in other language than default Needs work ). Updated to the patch in https://www.drupal.org/project/decoupled_router/issues/3111456#comment-1... πŸ› Unable to resolve path on node in other language than default Needs work and everything seems to be working again.

    So you need this in your composer.json

    "patches": {
      "drupal/decoupled_router": {
         "Unable to resolve path on node in other language than default": "https://www.drupal.org/files/issues/2024-08-05/decouple_router-3111456-resolve-language-issue-63--get-translation-re-rolled-and-good-redirect.patch"
      }
    }

    Running:
    Drupal core 10.3.5
    Subrequests 3.0.12 (if that matters)
    Next.js 1.6.3
    Decoupled Router 2.0.5

    Hope that helps
    Tom

Production build 0.71.5 2024