in admin_toolbar_toolbar_alter(), Trying to access array offset on value of type null

Created on 29 May 2025, 4 days ago

Problem/Motivation

Since updating to 3.6.0 we are seeing this in the logs:

 │              [%type] => Warning
  │              [@message] => __PHP_Incomplete_Class Object
  │                  (
  │                      [__PHP_Incomplete_Class_Name] => Drupal\Core\Render\Markup
  │                      [string:protected] => Trying to access array offset on value of type null
  │                  )
  │  
  │              [%function] => admin_toolbar_toolbar_alter()
  │              [%file] => /var/www/drupal/web/modules/drupal/admin_toolbar/admin_toolbar.module
                  [%line] => 39

That's a little funny since I see that key is in the install config, but the code could easily be more defensive and use an empty() check instead of checking exactly for TRUE.

Proposed resolution

Use empty()

🐛 Bug report
Status

Active

Version

3.6

Component

Code

Created by

🇺🇸United States pwolanin

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

Merge Requests

Comments & Activities

  • Issue created by @pwolanin
  • Merge request !153Issue #3527315 deffensive coding → (Merged) created by pwolanin
  • 🇺🇸United States pwolanin
  • Pipeline finished with Success
    4 days ago
    Total: 291s
    #509583
  • 🇺🇸United States pwolanin

    Possibly seeing this due to installing the site in our CI from existing config.

  • 🇫🇷France dydave

    Thanks Peter (@pwolanin)!

    Any chance this could be related to 🐛 Warning: Trying to access array offset on null in admin_toolbar_toolbar_alter() Active ?

    Thanks in advance!

  • 🇮🇪Ireland Michael.J.Gleeson

    This might help.

    Got this on my Local,
    Warning: Trying to access array offset on null in admin_toolbar_toolbar_alter() (line 39 of modules/contrib/admin_toolbar/admin_toolbar.module).

    $ddev drush config:get admin_toolbar.settings
    menu_depth: 4

    I went into config /admin/config/user-interface/admin-toolbar
    saved without changing

    ddev drush config: get admin_toolbar.settings
    enable_toggle_shortcut: false
    menu_depth: 4
    sticky_behavior: enabled
    hoverintent_behavior:
      enabled: true
      timeout: 250

    Solved the error for me. Hope this helps.

  • 🇺🇸United States pwolanin

    Yes, I think it's related to the closed issue, but I still think defensive coding is better than checking for exactly TRUE.

  • 🇫🇷France dydave

    Thanks a lot Peter (@pwolanin) for taking the time to look at this and give us some advice.

    When we first encountered this issue in #3440852-26: Make un-hover delay configurable , I suggested to @ressa to test with the update hook, which fixed it, but we didn't anticipate on other types of issues.

    We will try to stick to this approach in the future if there are more configuration changes with update hooks, to avoid as much as possible these types of issues.

    For the time being, I went ahead and merged the changes above at #8.

    This will most likely be released as a patch release, along with several other issues, if possible, in a 3.6.1 corrective version, for example.

    Marking issue as Fixed for now.

    Feel free to let us know if you spot anything else or if we missed anything, we would certainly be glad to help.
    Thanks in advance!

Production build 0.71.5 2024