I am trying to create a controller where I can edit user roles (just that, nothing more), and I'm king stuck.
I created a form type:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'roles', 'choice', [
'choices' => ['ROLE_ADMIN', 'ROLE_USER', 'ROLE_CUSTOMER'],
'expanded' => true,
'multiple' => true,
]
)
->add('send', 'submit');
}
First off, what's the best way to get roles? Is there a way to associate a label with them?
In the controller, I have the following:
public function editRolesAction($id_user)
{
$user = $this->user_repository->findOneById($id_user);
$form = $this->form_factory->create('dirital_user_roles_form_type', $user);
return [
'form' => $form->createView(),
'user' => $user
];
}
The problems that I have are:
- The form is not populated with the current user roles, how can I do this?
- When I receive the form, how can I update the user?
thanks a lot
source
share