PHP warning: Trying to access array offset on null in admin_toolbar_toolbar_alter() after update to 3.6.0

Created on 22 May 2025, 11 days ago

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!

🐛 Bug report
Status

Active

Version

3.6

Component

Code

Created by

🇫🇷France stoneteckel

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