UserGroups

Type
Class
Namespace
craft\services
Inherits
craft\services\UserGroups » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0

User Groups service.

An instance of the service is available via Craft::$app->userGroups.

View source (opens new window)

# Public Properties

# allGroups

Type
craft\models\UserGroup[]
Default value
null
Access
Read-only

View source (opens new window)

# assignableGroups

Type
craft\models\UserGroup[]
Default value
null
Access
Read-only

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
deleteGroup() Deletes a user group.
deleteGroupById() Deletes a user group by its ID.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
eagerLoadGroups() Eager-loads user groups onto the given users.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) 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() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) 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() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() (opens new window) Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
saveGroup() Saves a user group.
trigger() (opens new window) Triggers an event.

# deleteGroup()

Since
3.0.12

Deletes a user group.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the user group was deleted successfully

Throws

# deleteGroupById()

Deletes a user group by its ID.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the user group was deleted successfully

Throws

# eagerLoadGroups()

Since
3.6.0

Eager-loads user groups onto the given users.

View source (opens new window)

Arguments

# getAllGroups()

Returns all user groups.

View source (opens new window)

Returns

craft\models\UserGroup[]

# getAssignableGroups()

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

View source (opens new window)

Arguments

Returns

craft\models\UserGroup[]

# getGroupByHandle()

Gets a user group by its handle.

View source (opens new window)

Arguments

Returns

craft\models\UserGroup, null (opens new window)

# getGroupById()

Gets a user group by its ID.

View source (opens new window)

Arguments

Returns

craft\models\UserGroup, null (opens new window)

# getGroupByUid()

Gets a user group by its UID.

View source (opens new window)

Arguments

Returns

craft\models\UserGroup, null (opens new window)

# getGroupsByUserId()

Gets user groups by a user ID.

View source (opens new window)

Arguments

Returns

craft\models\UserGroup[]

# handleChangedUserGroup()

Handle any changed user groups.

View source (opens new window)

Arguments

# handleDeletedUserGroup()

Handle any deleted user groups.

View source (opens new window)

Arguments

# saveGroup()

Saves a user group.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# Constants

Constant Description
CONFIG_USERPGROUPS_KEY

# 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_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

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.