Skip to content

Grant new user role after 3 conditions are met

Version v2

Instead of downloading the archive, you can download and apply this model as a recipe (Drupal 10.3 or later):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Import recipe
composer require drupal-eca-recipe/eca_lib_0026

# Enable recipe with Drush (requires version 13 or later):
drush recipe ../recipes/eca_lib_0026

# Enable recipe without Drush:
cd web && php core/scripts/drupal recipe ../recipes/eca_lib_0026

# Rebuilding caches is optional, sometimes required:
drush cr

Purpose

This model automatically adds or removes a role from a user, when this gets updated, depending upon 3 conditions that are stored with the user entity. Only if all 3 conditions are met, the role gets added. In all other cases the role gets removed.

The creation of this module was recorded and the video with additional explanations can be watched here.

Dependencies

  • config
    • user.role.moderator
  • module
    • eca_base
    • eca_content
    • user

Used plugins

Events

Conditions

Actions

Changelog

v1

Initial release

v2

Replace role content_moderator with new role moderator to avoid extra dependencies that are derived from permissions