Search code examples
phpsymfonyfosuserbundlesonata-adminuser-roles

set role for users in edit form of sonata admin


I'm using Symfony 2.1 for a project. I use the FOSUserBundle for managing users & SonataAdminBundle for administration usage.

I have some questions about that:

  1. As an admin, I want to set roles from users in users edit form. How can I have access to roles in role_hierarchy? And how can I use them as choice fields so the admin can set roles to users?

  2. When I show roles in a list, it is shown as string like this:

    [0 => ROLE_SUPER_ADMIN] [1 => ROLE_USER] 
    

    How can I change it to this?

    ROLE_SUPER_ADMIN, ROLE_USER 
    

    I mean, having just the value of the array.


Solution

  • i found an answer for my first question!(but the second one in not answered yet..) i add the roles like below in configureFormFields function :

      protected function configureFormFields(FormMapper $formMapper) {
      //..
     $formMapper
     ->add('roles','choice',array('choices'=>$this->getConfigurationPool()->getContainer()->getParameter('security.role_hierarchy.roles'),'multiple'=>true ));
    }
    

    I would be very happy if anyone answers the second question :)