B
B
BANTIK2014-03-25 21:57:17
symfony
BANTIK, 2014-03-25 21:57:17

How to properly assign roles to groups in FOSUserBundle?

I use FOSUserBundle and the groups built into it, each of which has its own set of roles. The task is to make an administrative interface for assigning roles to groups (from security.role_hierarchy.roles). (I don't use sonata's admin panel generation bundles.) I.e. you need to add a field for multiple choice of roles to the form for creating / editing a group.
What is the right way to do it:

  1. Completely redefine GroupController from FOSUserBundle and form the required form directly from the controller ? ( in the mana, the symphony and the bundle are strongly discouraged from duplicating the logic ).
  2. Should I follow the path of overriding the edit / add group form and add a new role selection field to it? But here comes the questions:
    • how to get a list of all existing roles in the system from a form?
    • how to get a list of roles of a specific group from the form in order to make the choice Field Type field and mark already assigned roles as selected?


Or maybe there is some other truth to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-03-26
@BANTIK

Create a RoleType type for the form or something like that, where to form a list of available roles. The list of roles, as far as I remember, is available via DI as security.role_hierarchy.roles and it can be injected directly into the RoleType constructor (use FromType as a service they say).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question