Warning: Trying to access array offset on null in admin_toolbar_toolbar_alter()

Created on 22 May 2025, 11 days ago

Hello and thanks for this legendary module,

Problem/Motivation

After updating to 3.6.0, I've started receiving the error message below:

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

And the detail is:

admin_toolbar_toolbar_alter() (Line: 552)
Drupal\Core\Extension\ModuleHandler->alter() (Line: 80)
Drupal\toolbar\Element\Toolbar::preRenderToolbar()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 875)
Drupal\Core\Render\Renderer->doCallback() (Line: 432)
Drupal\Core\Render\Renderer->doRender() (Line: 504)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 87)
__TwigTemplate_1d3037525f04008f4f83ea633e439ee8->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: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
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: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

How can I solve it?

Best,
Orkut

๐Ÿ› Bug report
Status

Active

Version

3.6

Component

Code

Created by

๐Ÿ‡น๐Ÿ‡ทTurkey orkut murat yฤฑlmaz Istanbul

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

Comments & Activities

  • ๐Ÿ‡น๐Ÿ‡ทTurkey orkut murat yฤฑlmaz Istanbul

    Sorry, I forgot doing "drush updb" after the update.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    I'm not so sure, I'm seeing this warning on a clean install.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    Hmm looks like the config schema has changed, so "hoverintent_functionality" was in admin_toolbar_tools.settings and now moved to admin_toolbar.settings.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain pgrandeg

    Same here, appearing in a clean D11 installation. Configuration object admin_toolbar.settings is not well created after installing the module for any reason. After going to /admin/config/user-interface/admin-toolbar and saving without changes, the object exists and the error disappear

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom newaytech

    same error here after module upgrade and full cache clear.

    need to save on config pages as per prior post.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain pgrandeg
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexharries

    Just to explicitly write out the fix:

    Go to /admin/config/user-interface/admin-toolbar
    Click "Save"
    Done :-)

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom newaytech

    I just need to do that now across multiple test and production sites... is there a way to script this perhaps with drush?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexharries

    I mean, in fairness, if display errors is turned off in production, it shouldn't be a major issue :-)

    I have 15 or so affected sites but it's only causing me an eyesore on my local dev environments where displaying of errors is on.

    (You can turn off error displaying at /admin/config/development/logging ยฏ\_(ใƒ„)_/ยฏ )

    A

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom newaytech

    I guess so - will knock 'em down as I come across them then...

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil yseki

    Here is a patch.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    This appeared on all sites after auto-update and fails automated tests by producing an error.

    Can this fix please be released as a patch version

  • ๐Ÿ‡ฏ๐Ÿ‡ตJapan yoon thadar yee

    To resolve the problem, I navigated to:
    /admin/config/user-interface/admin-toolbar
    Clicked "Save" without changing any settings.
    This action refreshed the configuration and resolved the issue.
    Fix complete. ๐Ÿ‘

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    I don't understand .....

    Site administrators are not running database updates after updating their sites anymore?

    It has always been very standard to run DB updates after a site upgrade, whatever is being updated, whether core or contrib...

    Running DB updates should update the necessary configuration values, see:
    https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...

    which should prevent this type of errors from occurring.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    @dydave
    I can confirm that the database update has been applied successfully.

    However, if thereโ€™s a previous configuration exported - it reverts what this update does. As a result, for any sites that automatically update their dependencies, a manual configuration export is now required. This is a huge maintenance burden to now go through each website to re-export config.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    I mean .... if it's like that Alex (@alexgreyhead) we are never going to be able to make any changes to configuration objects in general ๐Ÿ˜…

    We have to be able to update configurations in our projects, otherwise we don't do anything anymore ๐Ÿ˜…

    I'm not a big fan of getting this patch applied as it adds "unnecessary" code in my sense....

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    The way we usually do this in our projects:

    Update the code base locally:
    composer update -W (for example with a global update)
    Update the configuration:
    drush cr
    drush updb
    Export the configuration changes:
    drush cex
    Commit/push the configuration changes:
    git add xxxx
    git commit
    git push

    This is always the standard procedure that we follow for any core or contrib upgrade and ensures any module is properly updated with its configuration inline before it gets imported.
    (drush deploy, for example)

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia alex.skrypnyk Melbourne

    drush deploy does it in bulk. so it will revert the changes that the update did. the user would not even know that there was a config change. a post deploy hook would help with this: it will run after all operations and will change the config in the DB. this config will then be shown as overridden and a developer can then run drush cex.

    I don't know who does it like you described these days:

    drush updb
    STOP TO Export the configuration changes
    drush cex

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexharries

    Hey, donโ€™t look at me; I found this via composer update working on my local dev :-P

    Never would have known there was a problem if Iโ€™d pushed straight to prod following my โ€œweโ€™ll test it in production; what could possibly go wrong?โ€ mantra :-D

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    I mean ... Alex, this doesn't seem related with Admin Toolbar specifically, but rather with the way site administrators maintain and deploy their configuration on their sites.

    This seems like a very generic problem, which is most likely the case with all other contrib modules and core ๐Ÿ˜…

    As far as the module is concerned, we "should" be able to consider everything was done in a very standard way.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia thomwilhelm Sydney

    Sorry for maybe asking a dumb question. But if you don't export config locally, how can you do a major upgrade from say Drupal 10.3 to 10.4? As when you run drush deploy, all the config changes performed by drush updb will be lost.

    This workflow seems pretty standard and is referenced in point 8 on Drupal's own guide here: https://www.drupal.org/docs/updating-drupal/updating-drupal-core-via-com... โ†’

    If you are using config management to deploy your config, make sure to export the config with drush config:export after the database update because some core updates may change the structure of the config files or introduce new values to them. Add the option --diff to view actual changes.

    So I'd say a lot of developers would be following this. Maybe it's different if you are managing 100's of site.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    Thanks a lot Thom (@thomwilhelm)!

    Looks like we have the same understanding of the complaints brought up in this issue:

    this doesn't seem related with Admin Toolbar specifically, but rather with the way site administrators maintain and deploy their configuration on their sites.

  • ๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen

    See also Deploying a Drupal update โ†’ where I attempted to document the most basic steps, and the correct order.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vishal.kadam Mumbai

    I also received this warning when updating the module to version 3.6.0, but it was resolved after running the database update.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain pgrandeg

    I enabled it today on fresh installation for d10, d11 and dcms and it is working. I don't know why it failed to me on fresh installation yesterday, but it is working good.

    So the key is to run database update as everybody is confirming or, only in case of need, just save the form /admin/config/user-interface/admin-toolbar.

    Please allow me to mark the ticket as closed as designed, since the discussion about configuration objects are not actually related with admin_toolbar.

  • ๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen

    Thanks, sounds good. I have added the solution in the Issue Summary under "Proposed resolution", so that users in need of help get a solution faster. Feel free to improve it or add more details :)

  • ๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    this is not an issue:
    - run updb after update
    - export config

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States chefigueroa Baltimore, MD

    #8 fixed my issue. Thanks.

  • ๐Ÿ‡น๐Ÿ‡ทTurkey orkut murat yฤฑlmaz Istanbul

    @ressa, thanks for the improvement:)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States attheshow

    #8 Was the correct approach for us. (Running database updates after updating the code wasn't enough to resolve the issue.) Thanks! ๐Ÿ˜Š๐Ÿ…

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance dydave

    @alex.skrypnyk: Sorry again for the additional work and noise on the updates.

    A fix was committed in the DEV branch in issue #3527315-8: in admin_toolbar_toolbar_alter(), Trying to access array offset on value of type null โ†’ and should be released in a patch version hopefully soon, after a few other "urgent" issues have been addressed (as many as possible).

    We will try to be more careful with these types of error cases in the future.
    Sorry again for the inconvenience and thanks in advance for your understanding. ๐Ÿ™

Production build 0.71.5 2024