Reputation: 1309
I have TYPO3 version 7.6.18.
I am making custom registration and I adding user in my code in controller:
$this->userRepository->add($user);
I need to set usergroup
I tried:
$user->setUsergroup(1);
But it calling error:
PHP Catchable Fatal Error: Argument 1 passed to TYPO3\CMS\Extbase\Domain\Model\FrontendUser::setUsergroup() must be an instance of TYPO3\CMS\Extbase\Persistence\ObjectStorage, integer given, called in /home/abenteuer/public_html/typo3conf/ext/feusersplus/Classes/Controller/NewController.php on line 68 and defined in /home/abenteuer/public_html/typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php line 192
I understand that I should pass argument to setUsergroup() which must be instance of TYPO3\CMS\Extbase\Persistence\ObjectStorage, but I don't know how to do it.
Help me please, anybody. I want to set usergroup, for example, with uid 1.
Upvotes: 1
Views: 2118
Reputation: 1300
I can't comment currently, but something you forgot, so i create an answer.
You can only use $this->userGroupRepository->findByIdentifier(1);
if you inject the Repository to your Controller with the following code:
/**
* userGroupRepository
*
* @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository
* @inject
*/
protected $userGroupRepository = null;
Upvotes: 0
Reputation: 6460
You'll need a separate repository for user groups (or start with the existing FrontendUserGroupRepository
) to retrieve the group(s):
$userGroup = $this->userGroupRepository->findByIdentifier(1);
Then you can simply do the following:
$user->addUsergroup($userGroup);
Afterwards add the $user
to your repository just like before.
Upvotes: 3