Problem/Motivation

Fix PHP Fatal error resulting in WSOD, occurring when saving AdminToolbarSettingsForm:

Error: Call to undefined method Drupal\Core\Menu\MenuLinkManager::invalidateAll() in Drupal\admin_toolbar\Form\AdminToolbarSettingsForm->submitForm() (line 84 of /var/www/html/web/modules/contrib/admin_toolbar/src/Form/AdminToolbarSettingsForm.php).

Detailed stacktrace :

#0 [internal function]: Drupal\admin_toolbar\Form\AdminToolbarSettingsForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#1 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
#2 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('admin_toolbar_s...', Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\admin_toolbar\Form\AdminToolbarSettingsForm), Object(Drupal\Core\Form\FormState))
#6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#7 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#25 {main}

Steps to reproduce

0 - Install the admin_toolbar module
1 - Browse to the Admin Toolbar settings at: /admin/config/user-interface/admin-toolbar
under: Home > Administration > Configuration > User interface > Admin Toolbar settings
2 - Save the form by clicking on the Save configuration button.
3 - Confirm the page crashes with WSOD error:

The website encountered an unexpected error. Try again later.

Error: Call to undefined method Drupal\Core\Menu\MenuLinkManager::invalidateAll() in Drupal\admin_toolbar\Form\AdminToolbarSettingsForm->submitForm() (line 107 of modules/contrib/admin_toolbar/src/Form/AdminToolbarSettingsForm.php).

Proposed resolution

This issue seems to have been introduced in commit:
https://git.drupalcode.org/project/admin_toolbar/-/commit/efb450aeb115f7...

It appears the values for $container->get were reversed when injecting the dependencies.

Solution: Set the injected dependencies in the correct order, for each respective property.

Additionally, add a basic automated test class to confirm the changes fix the issue.

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

DYdave created an issue. See original summary.

dydave’s picture

Status: Active » Needs review

Quick follow-up on this issue:

1 - Added automated tests for the 'AdminToolbarSettingsForm' at:
https://git.drupalcode.org/issue/admin_toolbar-3466125/-/commit/ac51e260...
and ran pipeline to demonstrate the tests would fail:
https://git.drupalcode.org/issue/admin_toolbar-3466125/-/pipelines/245075

2 - Fixed fatal error 'Call to undefined method Drupal\Core\Menu\MenuLinkManager::invalidateAll()' at:
https://git.drupalcode.org/issue/admin_toolbar-3466125/-/commit/ba61d199...
and ran pipeline to demonstrate the changes would fix the issue:
https://git.drupalcode.org/issue/admin_toolbar-3466125/-/pipelines/245084

Added testing for the Menu depth form setting:

  • Tested with default value (4), the display of the 'Admin Toolbar' admin menu item.
  • Tested with a depth of 2 that the menu item does not display.

 
✅ The merge request seems to be passing all tests, thus moving issue to Needs review.

We would greatly appreciate if a maintainer or someone with write permission could take a look at ticket's merge request MR!94 and let us know if there would be any more work needed.

Feel free to let us know if you have any questions or concerns on any of the changes in the merge request or any aspect of this ticket in general, we would surely be glad to help.
Thanks in advance for your feedback and reviews.

baluertl’s picture

Status: Needs review » Reviewed & tested by the community

The patch solves the exception when saving the module settings form on D11.0.0 core hence RTBC.

dydave’s picture

Title: Fix Fatal Error: Call to undefined method Drupal\Core\Menu\MenuLinkManager::invalidateAll() » [AdminToolbarSettingsForm] Fix Fatal Error: Call to undefined method Drupal\Core\Menu\MenuLinkManager::invalidateAll()
neurer’s picture

Can confirm MR !94 fixes this. Please commit.

teknocat’s picture

The same fix also needs to be applied to AdminToolbarToolsSettingsForm.

japerry made their first commit to this issue’s fork.

  • japerry committed f37bc920 on 3.x authored by dydave
    Issue #3466125 by dydave, japerry, teknocat: [AdminToolbarSettingsForm]...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

anybody’s picture

Hi @japerry would it be possible to tag a new release with this fix perhaps? Thanks :)