I am developing a simple CRUD to manage users/roles/groups of the application in which I am working. To manage users I\'m using FOSUserBundle. What I want to do
I added the functionality to add default group to the user during registration by overriding the confirmAction in Registration Controller
What I did is I overrided the Registration Controller in my project Bundle by defining the parent to FosUserBUndle .
Then created a function confirmedAction and in the body of the function added this code
$repository = $em->getRepository('AdminAdminBundle:Group');
$group = $repository->findOneByName('staff');
$em = $this->getDoctrine()->getEntityManager();
$user = $this->getUser();
$user->addGroup($group);
$userManager = $this->get('fos_user.user_manager');
$userManager->updateUser($user);
if (!is_object($user) || !$user instanceof FOS\UserBundle\Model\UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->render('FOSUserBundle:Registration:confirmed.html.twig',
['user' => $user]);
And it perfectly saved in db with group assignment.
Hope this will help some one in need as there is little information about the implementation in official fosuserbundle doc.