Skip to content

When a user is assigned to one or more groups

Sends a notification when a User has been assigned to one or more groups.

This trigger will catch:

  • Group assignments made by editing a user in the control panel, and
  • Group assignments made programmatically using Craft's internal API.

User group filters will be matched against the user's newly-assigned groups. The event fires when a user is added to a selected group, and not when they are removed from that group.

User Group Filters

Choose which user groups should fire this notification. Only users belonging to one of the selected groups will trigger it, and a user in multiple selected groups still receives only a single notification.

Ungrouped Users are users who belong to no group at all.

Selection is required

Check at least one group (or Ungrouped), or the notification won't fire.

Hidden if no groups exist

If no user groups are set up, this filter is skipped and every valid user will receive the notification.

Field Conditions

Field conditions restrict the notification based on the element's content, using Craft's native conditions framework. Build a rule set against the element's attributes and field values, and the notification will be sent only when every rule matches.

Must match all conditions

The condition builder evaluates every rule with AND semantics, so each rule must pass for the notification to be sent.

Twig variables

The object variable (and its user alias) is the User who was assigned. The dispatch data also carries:

  • groupIds (int[]) - all groups the user belongs to after the assignment
  • newGroupIds (int[]) - the groups that were just added
  • removedGroupIds (int[]) - the groups that were just removed
twig
{{ user.fullName }} was added to {{ newGroupIds|length }} group(s).

Examples

Welcome a new group member

twig
Hi {{ user.firstName }},

You have been added to the Editors group. You can now create and edit entries in the editorial sections.

Welcome aboard!

Notify admins of a sensitive role assignment

twig
{{ user.fullName }} ({{ user.email }}) was added to the Admins group by {{ currentUser.fullName }}.

Verify this change was intentional.

Skip unless a specific group was assigned

twig
{% set approvedVendors = craft.app.userGroups.getGroupByHandle('approvedVendors') %}

{% if approvedVendors.id not in newGroupIds %}
    {% skipMessage "User wasn't assigned to Approved Vendors." %}
{% endif %}

{{ user.fullName }} is now an approved vendor.