在 Sonata 管理员中,如果您希望覆盖安全角色处理程序,您必须覆盖 2 个服务
- sonata.user.editable_role_builder
- sonata.user.form.type.security_roles
定义如下所示
<services>
<service id="sonata.user.editable_role_builder" class="Acme\DemoBundle\Security\EditableRolesBuilder">
<argument type="service" id="security.context" />
<argument type="service" id="sonata.admin.pool" />
<argument>%security.role_hierarchy.roles%</argument>
</service>
<service id="sonata.user.form.type.security_roles" class="Acme\DemoBundle\Form\Type\SecurityRolesType">
<tag name="form.type" alias="sonata_security_roles" />
<argument type="service" id="sonata.user.editable_role_builder" />
</service>
</services>
参考见Sonata Admin Override Security Roles Handler