Craft 3 Class Reference

Class craft\services\UserGroups

Inheritance
craft\services\UserGroups » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/UserGroups.php

User Groups service.

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

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
deleteGroupById() Deletes a user group by its ID. craft\services\UserGroups
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getAllGroups() Returns all user groups. craft\services\UserGroups
getAssignableGroups() Returns the user groups that the current user is allowed to assign to another user. craft\services\UserGroups
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getGroupByHandle() Gets a user group by its handle. craft\services\UserGroups
getGroupById() Gets a user group by its ID. craft\services\UserGroups
getGroupsByUserId() Gets user groups by a user ID. craft\services\UserGroups
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
saveGroup() Saves a user group. craft\services\UserGroups
trigger() Triggers an event. yii\base\Component
Events
Event Type Description Defined By
EVENT_AFTER_DELETE_USER_GROUP craft\events\UserGroupEvent The event that is triggered after a user group is saved. craft\services\UserGroups
EVENT_AFTER_SAVE_USER_GROUP craft\events\UserGroupEvent The event that is triggered after a user group is saved. craft\services\UserGroups
EVENT_BEFORE_DELETE_USER_GROUP craft\events\UserGroupEvent The event that is triggered before a user group is deleted. craft\services\UserGroups
EVENT_BEFORE_SAVE_USER_GROUP craft\events\UserGroupEvent The event that is triggered before a user group is saved. craft\services\UserGroups

Method Details

deleteGroupById() public method #

Deletes a user group by its ID.

public boolean deleteGroupById ( \craft\services\int $groupId )
$groupId integer
throws craft\errors\WrongEditionException if this is called from Craft Personal or Client editions

getAllGroups() public method #

Returns all user groups.

public craft\models\UserGroup[] getAllGroups ( )

getAssignableGroups() public method #

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

public craft\models\UserGroup[] getAssignableGroups ( craft\elements\User $user null )
$user craft\elements\User, null The recipient of the user groups. If set, their current groups will be included as well.

getGroupByHandle() public method #

Gets a user group by its handle.

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

getGroupById() public method #

Gets a user group by its ID.

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

getGroupsByUserId() public method #

Gets user groups by a user ID.

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

saveGroup() public method #

Saves a user group.

public boolean saveGroup ( craft\models\UserGroup $group, \craft\services\bool $runValidation true )
$group craft\models\UserGroup The user group to be saved
$runValidation boolean Whether the user group should be validated
throws craft\errors\WrongEditionException if this is called from Craft Personal or Client editions

Event Details

EVENT_AFTER_DELETE_USER_GROUP event of type craft\events\UserGroupEvent #

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

EVENT_AFTER_SAVE_USER_GROUP event of type craft\events\UserGroupEvent #

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

EVENT_BEFORE_DELETE_USER_GROUP event of type craft\events\UserGroupEvent #

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

EVENT_BEFORE_SAVE_USER_GROUP event of type craft\events\UserGroupEvent #

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