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)
See detail below.
How can I solve it?
Best,
Orkut
Steps to reproduce
Proposed resolution
Solution: 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.
See also Deploying a Drupal update for the most basic steps, and the correct order.
Remaining tasks
User interface changes
API changes
Data model changes
Detailed error:
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)| Comment | File | Size | Author |
|---|---|---|---|
| #12 | admin_toolbar-array-offset-on-null-3525987-12.patch | 718 bytes | yseki |
Comments
Comment #2
orkutmuratyilmazSorry, I forgot doing "drush updb" after the update.
Comment #3
star-szrI'm not so sure, I'm seeing this warning on a clean install.
Comment #4
star-szrHmm looks like the config schema has changed, so "hoverintent_functionality" was in admin_toolbar_tools.settings and now moved to admin_toolbar.settings.
Comment #5
pgrandeg commentedSame 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
Comment #6
newaytech commentedsame error here after module upgrade and full cache clear.
need to save on config pages as per prior post.
Comment #7
pgrandeg commentedComment #8
alexgreyhead commentedJust to explicitly write out the fix:
Go to /admin/config/user-interface/admin-toolbar
Click "Save"
Done :-)
Comment #9
newaytech commentedI just need to do that now across multiple test and production sites... is there a way to script this perhaps with drush?
Comment #10
alexgreyhead commentedI 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
Comment #11
newaytech commentedI guess so - will knock 'em down as I come across them then...
Comment #12
yseki commentedHere is a patch.
Comment #13
alex.skrypnykThis 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
Comment #14
yoon thadar yee commentedTo 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. 👍
Comment #15
dydave commentedI 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.
Comment #16
alex.skrypnyk@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.
Even more - if sites have updb + cim running (drush deploy), they will always end up with reverted changes. People would not even realise that there was a change as their config will not be overwritten.
I would provide an additional post deploy hook to mitigate this.
But this this specific case - can we please just fix the condition and release a patch
Comment #17
dydave commentedI mean .... if it's like that Alex (@alex.skrypnyk) 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....
Comment #18
dydave commentedThe 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)
Comment #19
alex.skrypnykdrush 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
So not only there is now an error being thrown in UI and blocking automated tests in consumer site's CI, but also this now requires to break out of the established deployment process to manually re-export config.
This looks like a breaking change to me and should be accommodated in code to support both old and new version at least until the next minor version of the module.
Comment #20
alexgreyhead commentedHey, 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
Comment #21
dydave commentedI mean ... Alex (@alex.skrypnyk), 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 and we've provided a valid method to prevent the error described in this ticket from occurring.
Comment #22
thomwilhelm commentedSorry 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...
So I'd say a lot of developers would be following this. Maybe it's different if you are managing 100's of site.
Comment #23
dydave commentedThanks a lot Thom (@thomwilhelm)!
Looks like we have the same understanding of the complaints brought up in this issue:
Comment #24
ressaSee also Deploying a Drupal update where I attempted to document the most basic steps, and the correct order.
Comment #25
vishal.kadamI also received this warning when updating the module to version 3.6.0, but it was resolved after running the database update.
Comment #26
pgrandeg commentedI 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.
Comment #27
ressaThanks, 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 :)
Comment #28
ressaComment #29
jannakha commentedthis is not an issue:
- run updb after update
- export config
Comment #30
jannakha commentedComment #31
ricardochefigueroa commented#8 fixed my issue. Thanks.
Comment #32
orkutmuratyilmaz@ressa, thanks for the improvement:)
Comment #33
attheshow commented#8 Was the correct approach for us. (Running database updates after updating the code wasn't enough to resolve the issue.) Thanks! 😊🏅
Comment #34
dydave commented@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. 🙏