UserGroup vs Concrete\Core\User\Group\Group

Permalink
Hi,

I try to create a new user group during package install using

Group::add($gName, $gDescription, $parentGroup, $pkg, null);


(Group references to Concrete\Core\User\Group\Group)

...I get this error message from the dashboard

Argument 1 passed to Concrete\Core\Tree\Node\Type\Group::setTreeNodeGroup() must be an instance of Group, instance of Concrete\Core\User\Group\Group given, called in /home/msci/public_html/concrete/src/Tree/Node/Type/Group.php on line 114 and defined

When I look that file, it uses Group as UserGroup. Should I use the UserGroup or the Group from Core\User\Group namespace?

 
Darragi replied on at Permalink Reply
Hi FrankX,

Your request is not really clear, but i think that you have a conflict with "use" statement.

Okey, in general if you want to use to two classes with same name and different namespaces then you have to use 'as' statement.

In your case you have 'Concrete\Core\Tree\Node\Type\Group' and 'Concrete\Core\User\Group\Group', so your class will looks like:
<?php 
namespace Concrete\Package\YouPackage;
use Package;
use \Concrete\Core\User\Group\Group as UserGroup;
use \Concrete\Core\Tree\Node\Type\Group as TreeGroup;
class Controller extends Package
{
   ....
  function install(){
        // add UserGroup
        UserGroup::add($gName, $gDescription);
        // add Tree Group
        TreeGroup::add($group, $parent);
  }


Hope that helps.

Regards,
Darragi
FrankX replied on at Permalink Reply
Thanks for your answer Darragi, I try to clarify myself.

In my package controller file I try to create a new user group and I use the Group::add function. The group references to Concrete\Core\User\Group\Group. When I install the package (and the package controller is run) I get the error message I quoted on my first post. That error message came from a core source file that used a UserGroup class.

Basically my problem is, how do I create a new user group during package install?
Darragi replied on at Permalink Reply
OK FrankX, So you have to use UserGroup as mentioned previously and don't forget the 'use' statement.

PS : note that the add user group method has only two parameters gName and gDescription.

Good luck.
Darragi