MenuPositionLink::getTitle() crashes when there is not current link

Created on 5 November 2020, about 4 years ago
Updated 29 May 2023, over 1 year ago

Problem/Motivation

We are using simple_sitemap to generate a sitemap with Drush. However, this fails when the menu contains virtual links generated by menu_position:

> TypeError: Argument 2 passed to Drupal\Core\Controller\TitleResolver::getTitle() must be an instance of Symfony\Component\Routing\Route, null given, called in /var/www/web/modules/contrib/menu_position/src/Plugin/Menu/MenuPositionLink.php on line 157 in /var/www/web/core/lib/Drupal/Core/Controller/TitleResolver.php on line 50 #0 /var/www/web/modules/contrib/menu_position/src/Plugin/Menu/MenuPositionLink.php(157): Drupal\Core\Controller\TitleResolver->getTitle(Object(Symfony\Component\HttpFoundation\Request), NULL)
> #1 /var/www/web/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php(238): Drupal\menu_position\Plugin\Menu\MenuPositionLink->getTitle()
> #2 /var/www/web/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php(231): Drupal\Core\Menu\DefaultMenuLinkTreeManipulators->generateIndexAndSort(Array)
> #3 [internal function]: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators->generateIndexAndSort(Array)
> #4 /var/www/web/core/lib/Drupal/Core/Menu/MenuLinkTree.php(148): call_user_func(Array, Array)
> #5 /var/www/web/modules/contrib/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php(106): Drupal\Core\Menu\MenuLinkTree->transform(Array, Array)
> #6 /var/www/web/modules/contrib/simple_sitemap/src/Queue/QueueWorker.php(148): Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityMenuLinkContentUrlGenerator->getDataSets()
> #7 /var/www/web/modules/contrib/simple_sitemap/src/Queue/QueueWorker.php(187): Drupal\simple_sitemap\Queue\QueueWorker->queue(NULL)
> #8 /var/www/web/modules/contrib/simple_sitemap/src/Queue/QueueWorker.php(219): Drupal\simple_sitemap\Queue\QueueWorker->rebuildQueue()
> #9 /var/www/web/modules/contrib/simple_sitemap/src/Queue/BatchTrait.php(65): Drupal\simple_sitemap\Queue\QueueWorker->generateSitemap()
> #10 [internal function]: Drupal\simple_sitemap\Queue\QueueWorker::doBatchGenerateSitemap(Object(DrushBatchContext))
> #11 /var/www/vendor/drush/drush/includes/batch.inc(254): call_user_func_array('Drupal\\simple_s...', Array)
> #12 /var/www/vendor/drush/drush/includes/batch.inc(199): _drush_batch_worker()
> #13 /var/www/vendor/drush/drush/includes/batch.inc(100): _drush_batch_command('77')
> #14 /var/www/vendor/drush/drush/src/Drupal/Commands/core/BatchCommands.php(22): drush_batch_command('77')
> #15 [internal function]: Drush\Drupal\Commands\core\BatchCommands->process('77', Array)
> #16 /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
> #17 /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #18 /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #19 /var/www/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
> #20 /var/www/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #21 /var/www/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #22 /var/www/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #23 /var/www/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #24 /var/www/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
> #25 /var/www/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
> #26 /var/www/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
> #27 /var/www/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/vendor...')
> #28 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
> #29 /usr/local/bin/drush(10): require('phar:///usr/loc...')
> #30 {main}

Steps to reproduce

  1. Install menu_position 1.0.0-beta1 and simple_sitemap 3.5.0
  2. Add a menu position rule to the main menu
  3. Run drush simple-sitemap:generate

Proposed resolution

Don't try to call TitleResolver::getTitle() when there is no current route.

Remaining tasks

I will submit a patch.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France prudloff Lille

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024