2026 Community Survey results are here! See how the Craft CMS community works. results are live!

Dynamic User Group Assignment in Craft CMS

This video demonstrates implementing event listeners in Craft CMS 5 to dynamically modify user groups, covering both additive group assignment and replacement assignment.

In this video, Ryan demon­strates imple­ment­ing dynam­ic user group man­age­ment in Craft CMS 5 using event lis­ten­ers with­in a site mod­ule. The core imple­men­ta­tion uses EVENT_AFTER_SAVE on Entry ele­ments to detect when authors reach pub­lish­ing thresh­olds, then mod­i­fies their group assign­ments using Craft’s Users ser­vice. The code shows prop­er event han­dling pat­terns includ­ing check­ing for draft sta­tus, ver­i­fy­ing author exis­tence, and using the assignUserToGroups() method which accepts an array of group IDs.

Ryan explores two dis­tinct approach­es for group assign­ment: addi­tive (pre­serv­ing exist­ing groups while adding new ones using array merg­ing) and replace­ment (com­plete­ly replac­ing all group assign­ments with a new set).

Craft Version
Craft 5
Instructor
Ryan Irelan
Date Published
September 10, 2025