UserGroups

Type
Class
Namespace
craft\services
Inherits
craft\services\UserGroups » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

User Groups service.

An instance of the User Groups service is globally accessible in Craft via Craft::$app->userGroups.

View source

Public Properties

PropertyDescription
$allGroupscraft\models\UserGroup[]
$assignableGroupscraft\models\UserGroup[]
$behaviorsyii\base\Behavior – List of behaviors attached to this component

$allGroups

Signature

public craft\models\UserGroup[] getAllGroups ( )

$assignableGroups

Signature

public craft\models\UserGroup[] getAssignableGroups ( craft\elements\User $user = null )

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
deleteGroup()Deletes a user group.
deleteGroupById()Deletes a user group by its ID.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getAllGroups()Returns all user groups.
getAssignableGroups()Returns the user groups that the current user is allowed to assign to another user.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getGroupByHandle()Gets a user group by its handle.
getGroupById()Gets a user group by its ID.
getGroupsByUserId()Gets user groups by a user ID.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
saveGroup()Saves a user group.
trigger()Triggers an event.

deleteGroup()

Deletes a user group.

View source

Arguments

Returns

boolean – Whether the user group was deleted successfully

Throws

Signature

public boolean deleteGroup ( craft\models\UserGroup $group )

deleteGroupById()

Deletes a user group by its ID.

View source

Arguments

  • $groupId (integer) – The user group's ID

Returns

boolean – Whether the user group was deleted successfully

Throws

Signature

public boolean deleteGroupById ( \craft\services\int $groupId )

getAllGroups()

Returns all user groups.

View source

Returns

craft\models\UserGroup[]

Signature

public craft\models\UserGroup[] getAllGroups ( )

getAssignableGroups()

Returns the user groups that the current user is allowed to assign to another user.

View source

Arguments

  • $user (craft\elements\User, null) – The recipient of the user groups. If set, their current groups will be included as well.

Returns

craft\models\UserGroup[]

Signature

public craft\models\UserGroup[] getAssignableGroups ( craft\elements\User $user = null )

getGroupByHandle()

Gets a user group by its handle.

View source

Arguments

Returns

craft\models\UserGroup, null

Signature

public craft\models\UserGroup, null getGroupByHandle ( \craft\services\string $groupHandle )

getGroupById()

Gets a user group by its ID.

View source

Arguments

Returns

craft\models\UserGroup, null

Signature

public craft\models\UserGroup, null getGroupById ( \craft\services\int $groupId )

getGroupsByUserId()

Gets user groups by a user ID.

View source

Arguments

Returns

craft\models\UserGroup[]

Signature

public craft\models\UserGroup[] getGroupsByUserId ( \craft\services\int $userId )

saveGroup()

Saves a user group.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveGroup ( craft\models\UserGroup $group, \craft\services\bool $runValidation = true )

Events

EVENT_AFTER_DELETE_USER_GROUP

Type
craft\events\UserGroupEvent

The event that is triggered after a user group is saved.

EVENT_AFTER_SAVE_USER_GROUP

Type
craft\events\UserGroupEvent

The event that is triggered after a user group is saved.

EVENT_BEFORE_DELETE_USER_GROUP

Type
craft\events\UserGroupEvent

The event that is triggered before a user group is deleted.

EVENT_BEFORE_SAVE_USER_GROUP

Type
craft\events\UserGroupEvent

The event that is triggered before a user group is saved.