When trying to activate the module on a machine with PHP 8.1 I am seeing the following:

TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in method_exists() (line 224 of /home/sites/sitename/public_html/modules/contrib/menu_token/src/Service/TokenReplacer.php)

#0 /home/sites/sitename/public_html/modules/contrib/menu_token/src/Service/TokenReplacer.php(224): method_exists(NULL, 'isAnonymous')
#1 /home/sites/sitename/public_html/modules/contrib/menu_token/menu_token.module(328): Drupal\menu_token\Service\TokenReplacer->replaceExoticToken('[current-user:a...', 'account-name', Object(Drupal\Core\Render\BubbleableMetadata))
#2 [internal function]: menu_token_tokens('current-user', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#3 /home/sites/sitename/public_html/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('menu_token_toke...', Array)
#4 /home/sites/sitename/public_html/core/lib/Drupal/Core/Utility/Token.php(304): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#5 /home/sites/sitename/public_html/core/lib/Drupal/Core/Utility/Token.php(196): Drupal\Core\Utility\Token->generate('current-user', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#6 /home/sites/sitename/public_html/modules/contrib/menu_token/menu_token.module(342): Drupal\Core\Utility\Token->replace('Welcome [curren...', Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#7 /home/sites/sitename/public_html/modules/contrib/menu_token/menu_token.module(406): replace_links_with_tokens(Object(Drupal\token\Token), 'title', Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#8 /home/sites/sitename/public_html/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): menu_token_menu_links_discovered_alter(Array, NULL, NULL)
#9 /home/sites/sitename/public_html/core/lib/Drupal/Core/Menu/MenuLinkManager.php(166): Drupal\Core\Extension\ModuleHandler->alter('menu_links_disc...', Array)
#10 /home/sites/sitename/public_html/core/lib/Drupal/Core/Menu/MenuLinkManager.php(189): Drupal\Core\Menu\MenuLinkManager->getDefinitions()
#11 /home/sites/sitename/public_html/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(82): Drupal\Core\Menu\MenuLinkManager->rebuild()
#12 /home/sites/sitename/public_html/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(70): Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->menuLinksRebuild()
#13 [internal function]: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->onRouterRebuild(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#14 /home/sites/sitename/public_html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#15 /home/sites/sitename/public_html/core/lib/Drupal/Core/Routing/RouteBuilder.php(197): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...')
#16 /home/sites/sitename/public_html/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#17 /home/sites/sitename/public_html/core/lib/Drupal/Core/Extension/ModuleInstaller.php(382): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#18 /home/sites/sitename/public_html/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install(Array, true)
#19 /home/sites/sitename/vendor/drush/drush/src/Drupal/Commands/pm/PmCommands.php(88): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array, true)
#20 [internal function]: Drush\Drupal\Commands\pm\PmCommands->install(Array, Array)
#21 /home/sites/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#22 /home/sites/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#23 /home/sites/sitename/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#24 /home/sites/sitename/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#25 /home/sites/sitename/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/sites/sitename/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /home/sites/sitename/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /home/sites/sitename/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /home/sites/sitename/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 /home/sites/sitename/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 /home/sites/sitename/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#32 /home/sites/sitename/vendor/drush/drush/includes/preflight.inc(18): require('/home/sites/pos...')
#33 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
#34 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#35 {main}

Comments

Christopher Riley created an issue. See original summary.

Christopher Riley’s picture

Anyone have a suggestion as to what I need to change to get this working I need to get a new site launched.

tienwang’s picture

I created a patch for 9.1.x. Please check.

tienwang’s picture

StatusFileSize
new1.01 KB

Sorry. Something was missing. Please try this one.

kwfinken’s picture

Status: Active » Reviewed & tested by the community

That patch worked for me on Drupal 9.4.5, PHP 8.1.

loopy1492’s picture

Worked for me on 9.5.1 with php 8. Looking forward to it being added to a release. Probably want this done before Drupal 10.

afagioli’s picture

Worked for me on

Drupal version : 9.4.8
PHP binary : /usr/bin/php8.1
PHP OS : Linux

  • DevElCuy committed addc25a0 on 9.1.x authored by tienwang
    Issue #3276289 by tienwang, Christopher Riley, kwfinken, loopy1492,...
develcuy’s picture

Status: Reviewed & tested by the community » Fixed

Thank you guys! You rock!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.