[英]Sonata admin: user_block is not displayed
I'm using SonataAdmin and I can't see the user block displayed in the template (on the top right) although I have replaced it with my custom template as mentioned in the configuration here https://sonata-project.org/bundles/admin/3-x/doc/reference/templates.html我正在使用 SonataAdmin,但我看不到模板中显示的用户块(在右上角),尽管我已将其替换为我的自定义模板,如此处的配置中所述https://sonata-project.org/bundles /admin/3-x/doc/reference/templates.html
I'm using SonataUserBundle and this is my configuration:我正在使用 SonataUserBundle,这是我的配置:
sonata_admin:
templates:
user_block: ApplicationSonataUserBundle:Default:user_block.html.twig
and these are the versions I'm using:这些是我正在使用的版本:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"sonata-project/admin-bundle": "^3.43",
"sonata-project/doctrine-orm-admin-bundle": "^3.7",
"sonata-project/user-bundle": "4.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0"
},
I get no error however the user icon on the top right is not displayed !我没有收到错误但是右上角的用户图标没有显示!
What am I missing here ?我在这里错过了什么?
ok so I found that sonata is testing if the user has role_admin
to display the user_block
as mentioned here https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/standard_layout.html.twig#L194好的,所以我发现奏鸣曲正在测试用户是否具有
role_admin
来显示这里提到的user_block
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/standard_layout.html。树枝#L194
look for this condition:寻找这个条件:
{% if app.user and is_granted(sonata_admin.adminPool.getOption('role_admin')) %}
and since all users has the role ROLE_USER
I just need to give this information to sonata, in the config.yml file, so it will display the user_block
to all connected users, like so:由于所有用户都有角色
ROLE_USER
我只需要在config.yml文件中将此信息提供给奏鸣曲,因此它将向所有连接的用户显示user_block
,如下所示:
sonata_admin:
security:
role_admin: ROLE_USER
sonata_admin:
security:
role_admin: foobar_token
class UserBlockVoter extends Voter
{
protected function supports($attribute, $subject)
{
return 'foobar_token' == $attribute;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return true;
}
}
if changing roles is not the case - create a voter for custom-named "role_admin" attribute, since decision of showing/hiding is based on security checker.如果不是更改角色 - 为自定义命名的“role_admin”属性创建投票者,因为显示/隐藏的决定基于安全检查器。
furthermore, you could check "User" instance inside voter with more complex rules than just "ROLE_ADMIN"此外,您可以使用比“ROLE_ADMIN”更复杂的规则检查选民中的“用户”实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.