src/Sulu/Bundle/SecurityBundle/UserManager/UserManager.php
private function addUserGroup(UserInterface $user, $userGroupData)
    {
        $group = $this->groupRepository->findGroupById($userGroupData['group']['id']);

        if (!$group) {
            throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroupData['group']['id']);
        }

        $userGroup = new UserGroup();
        $userGroup->setUser($user);
        $userGroup->setGroup($group);
        $userGroup->setLocale(json_encode($userGroupData['locales']));
        $this->em->persist($userGroup);

        $user->addUserGroup($userGroup);

        return true;
    }
private function addUserGroup(UserInterface $user, $userGroupData)
    {
        $group = $this->groupRepository->findGroupById($userGroupData['group']['id']);

        if (!$group) {
            throw new EntityNotFoundException($this->groupRepository->getClassName(), $userGroupData['group']['id']);
        }

        $userGroup = new UserGroup();
        $userGroup->setUser($user);
        $userGroup->setGroup($group);
        $userGroup->setLocale(json_encode($userGroupData['locales']));
        $this->em->persist($userGroup);

        $user->addUserGroup($userGroup);

        return true;
    }
private function addUserGroup ( UserInterface $ user , $ userGroupData ) { $ group = $ this -> groupRepository -> findGroupById ( $ userGroupData [ 'group' ] [ 'id' ] ) ; if ( ! $ group ) { throw new EntityNotFoundException ( $ this -> groupRepository -> getClassName ( ) , $ userGroupData [ 'group' ] [ 'id' ] ) ; } $ userGroup = new UserGroup ( ) ; $ userGroup -> setUser ( $ user ) ; $ userGroup -> setGroup ( $ group ) ; $ userGroup -> setLocale ( json_encode ( $ userGroupData [ 'locales' ] ) ) ; $ this -> em -> persist ( $ userGroup ) ; $ user -> addUserGroup ( $ userGroup ) ; return true ; }
Adds a new UserGroup to the given user.

@param UserInterface $user
@param $userGroupData

@throws \Sulu\Component\Rest\Exception\EntityNotFoundException

@return bool
Adds a new UserGroup to the given user .