XF 2.0 add to secondary group in the process of registration

gotski

Active member
Hello, I created extend, I want to add my new members to secondary user group after registration, but I'll received error: "LogicException: Attempted to set 'secondary_group_ids' while a save was pending without forceSet in src\XF\Mvc\Entity\Entity.php at line 529"

are there any ideas, how can I solve my task?

Thanks!


Code:
class User extends XFCP_User {

    protected function _postSave()
    {
       
        parent::_postSave();      
       
        if ($this->isInsert())
        {

        $userGroupChange = $this->app()->service('XF:User\UserGroupChange');
        $userGroupChange->addUserGroupChange($this->user_id, '', '5');

        }      
       
    }

}
 
XF2 has far more extension points for specific actions than XF1 ever did. Notably, there's a "XF\Service\User\Registration" service which has a number of methods you could use to apply additional user groups or other default registration values. Arguably doesn't need to use the user group change service, either, (probably can't for a user which doesn't yet exist) -- you could just set the values directly before the user is saved.
 
Back
Top Bottom