I am using the FOS Userbundle and I want to add new role such as ROLE_ZZZ.
What is the best way to do this? Thanks.
The FOSUserbundle
does not provide a role-entity. You have to implement it yourself by implementing the Symfony\Component\Security\Core\Role\RoleInterface
.
It should look like this role-entity.
After that you have to create the user-role relationship and assign the role to the user. A full tutorial can be found here to implement a new role in fosuserbundle.
I think a valid (clean and simple enough) way to create a new role and integrate it with FOSUserBundle is
1) Add a new role through security.yml
security:
role_hierarchy:
ROLE_ZZZ: [ROLE_USER, OTHER_PERMISSION_1, OTHER_PERMISSION_2, ...]
2) Create a FOSUserBundle group (group handling doc here) and asign that role (and only that role) to the group.
Then users can be added to that group as you need to.