addRole() public méthode

public addRole ( $role )
 protected function onSuccess(UserInterface $user, $confirmation)
 {
     // Note: if you plan on modifying the user then do it before calling the
     // parent method as the parent method will flush the changes
     $user->addRole('ROLE_NORMAL_USER');
     $user->setRegistrationStatus('complete');
     $user->setSalt($this->random_key_generator(20));
     parent::onSuccess($user, $confirmation);
     // otherwise add your functionality here
 }
Exemple #2
0
 /**
  *
  */
 public function updateRoles(UserInterface $user)
 {
     $roles = $user->getRoles();
     $roleRepository = $this->objectManager->getRepository('WeavingTheWebUserBundle:Role');
     foreach ($roles as $role) {
         $roleName = (string) $role;
         $roleEntity = $roleRepository->findOneByRole($roleName);
         $user->removeRole($role);
         $user->addRole($roleEntity);
     }
 }