Problem/Motivation
Hi!
My environment:
Drupal 11.1.7
PHP 8.3.21
Admin Toolbar: 3.6.0
After updating to admin_toolbar 3.6.0 from version 3.5.3, I encountered the following warning on every pages:
Warning: Trying to access array offset on null in admin_toolbar_toolbar_alter() (line 39 of modules/contrib/admin_toolbar/admin_toolbar.module).
admin_toolbar_toolbar_alter() (Line: 459)
Drupal\Core\Extension\ModuleHandler->alter() (Line: 80)
Drupal\toolbar\Element\Toolbar::preRenderToolbar()
call_user_func_array() (Line: 107)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 830)
Drupal\Core\Render\Renderer->doCallback() (Line: 387)
Drupal\Core\Render\Renderer->doRender() (Line: 459)
Drupal\Core\Render\Renderer->doRender() (Line: 203)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 85)
__TwigTemplate_3ed8cb050c2d0018f52530c631522f0f->doDisplay() (Line: 388)
Twig\Template->yield() (Line: 344)
Twig\Template->display() (Line: 359)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 446)
Drupal\Core\Render\Renderer->doRender() (Line: 203)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
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: 32)
Drupal\big_pipe\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: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Steps to reproduce
1. Update admin_toolbar to version 3.6.0 from version 3.5.3.
2. Go to any page (or any admin page).
3. Observe the PHP warning in the browser if error display is enabled.
Proposed resolution
Add a check to ensure the `$hoverintent_behavior` variable is an array before accessing array keys, with something like this:
$hoverintent_behavior = $admin_toolbar_config->get('hoverintent_behavior');
if (is_array($hoverintent_behavior) && !empty($hoverintent_behavior['enabled'])) {
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree.hoverintent';
$timeout = isset($hoverintent_behavior['timeout']) ? $hoverintent_behavior['timeout'] : 250;
$items['administration']['#attached']['drupalSettings']['hoverIntentTimeout'] = $timeout;
}
else {
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree.hover';
}
Let me know if you need more information. Thanks for maintaining this module!
Comments
Comment #2
avpadernoComment #3
ressaThanks for reporting @stoneteckel, I get the warning shown if I install version 3.5.3, delete the hoverIntent config with
drush config:delete admin_toolbar.settings hoverintent_behavior, update to version 3.6 and access pages.EDIT: As others have suggested, a database update could be the solution.
Comment #4
dallen33 commentedAfter upgrading to 3.6, doing a
drush updbresolved this error for me.Comment #5
sebastixMake sure your database is up to date and there are no updates. With the upgrade to 3.6 there are updates which have to be processed and probably cause these warnings on your installation.
Comment #6
ressaComment #7
dydave commentedClosing in favor of #3525987: Warning: Trying to access array offset on null in admin_toolbar_toolbar_alter()
Thanks everyone!
Comment #8
papagrande