Reputation: 6036
I recently did a vendors/install and now my sonata admin is broken with the following error:
Item "roles" for "" does not exist in SonataAdminBundle::standard_layout.html.twig at line 92
Here is the twig code:
{% if app.security %}
{% for role in app.security.token.roles %}
{% if not allowed %}
{% set allowed = role.role == 'ROLE_SONATA_ADMIN' %}
{% endif %}
{% endfor %}
{% endif %}
Anyone have any thoughts?
Thanks!
Upvotes: 0
Views: 3284
Reputation: 41
I had the same problem with the last version of SonataAdminBundle. This problem appears if you allow for everybody opening your admin panel. This is not usuall solution at least for the working site.
To grant access to your admin panel for everybody do the following. Place the path /admin under firewall, add into the file security.yml in the section security.firewals the rows
admin_area:
pattern: ^/admin
anonymous: ~
Thus each client will be authorized as anonymous user with existing token and the errors will not appear.
P.S. Sorry for grammar mistakes, but I think everybody will understand me :)
Upvotes: 0
Reputation: 9967
Here is the fix : https://github.com/Wiakowe/SonataAdminBundle/commit/e139527c05b22176ee3efab987ebe752668d4489
Remove lines 90-99 and replace with the following:
{% if app.security and is_granted('ROLE_SONATA_ADMIN') %}
Upvotes: 0
Reputation: 238
I searched through admin bundle with blame option and it comes from a commit 7 days ago
So what you have to do is go to deps.lock
Find the adminBundle commit hash(In my case it started with 4a....) replace the hash with 25b401e6271ee0fd896d700d0328b06994e4e138 which is commit before the commit that cause problem
I tried it and dashboard works correctly
Good luck
EDIT
Be careful not to use php bin/vendor update since it will update the commit hash
Use php bin/vendor install
Upvotes: 1