UserGroups ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\UserGroups » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
User Groups service.
An instance of the service is available via Craft::$app->getUserGroups().
Public Properties ​
| Property | Description |
|---|---|
| allGroups | craft\models\UserGroup[] |
| assignableGroups | craft\models\UserGroup[] |
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
allGroups ​
- Type
- craft\models\UserGroup[]
- Default value
null- Access
- Read-only
assignableGroups ​
- Type
- craft\models\UserGroup[]
- Default value
null- Access
- Read-only
Public Methods ​
| Method | Description |
|---|---|
| __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 a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be 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. |
| eagerLoadGroups() | Eager-loads user groups onto the given users. |
| 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. |
| getGroupByUid() | Gets a user group by its UID. |
| getGroupsByUserId() | Gets user groups by a user ID. |
| handleChangedUserGroup() | Handle any changed user groups. |
| handleDeletedUserGroup() | Handle any deleted user groups. |
| 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 for this component. |
| 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() ​
- Since
- 3.0.12
Deletes a user group.
Arguments ​
$group(craft\models\UserGroup) – The user group
Returns ​
boolean – Whether the user group was deleted successfully
Throws ​
- craft\errors\WrongEditionException
if this is called from Craft Solo edition
deleteGroupById() ​
Deletes a user group by its ID.
Arguments ​
$groupId(integer) – The user group's ID
Returns ​
boolean – Whether the user group was deleted successfully
Throws ​
- craft\errors\WrongEditionException
if this is called from Craft Solo edition
eagerLoadGroups() ​
- Since
- 3.6.0
Eager-loads user groups onto the given users.
Arguments ​
$users(craft\elements\User[]) – The users to eager-load user groups onto
getAllGroups() ​
Returns all user groups.
Returns ​
getAssignableGroups() ​
Returns the user groups that the current user is allowed to assign to another user.
Arguments ​
$user(craft\elements\User, null) – The recipient of the user groups. If set, their current groups will be included as well.
Returns ​
getGroupByHandle() ​
Gets a user group by its handle.
Arguments ​
$groupHandle(string)
Returns ​
getGroupById() ​
Gets a user group by its ID.
Arguments ​
$groupId(integer)
Returns ​
getGroupByUid() ​
Gets a user group by its UID.
Arguments ​
$uid(string)
Returns ​
getGroupsByUserId() ​
Gets user groups by a user ID.
Arguments ​
$userId(integer)
Returns ​
handleChangedUserGroup() ​
Handle any changed user groups.
Arguments ​
$event(craft\events\ConfigEvent)
handleDeletedUserGroup() ​
Handle any deleted user groups.
Arguments ​
$event(craft\events\ConfigEvent)
saveGroup() ​
Saves a user group.
Arguments ​
$group(craft\models\UserGroup) – The user group to be saved$runValidation(boolean) – Whether the user group should be validated
Returns ​
Throws ​
- craft\errors\WrongEditionException
if this is called from Craft Solo edition
Events ​
EVENT_AFTER_DELETE_USER_GROUP ​
The event that is triggered after a user group is saved.
EVENT_AFTER_SAVE_USER_GROUP ​
The event that is triggered after a user group is saved.
EVENT_BEFORE_APPLY_GROUP_DELETE ​
- Type
- craft\events\UserGroupEvent
- Since
- 3.1.0
The event that is triggered before a user group delete is applied to the database.
EVENT_BEFORE_DELETE_USER_GROUP ​
The event that is triggered before a user group is deleted.
EVENT_BEFORE_SAVE_USER_GROUP ​
The event that is triggered before a user group is saved.