user_user_role_insert

user_user_role_insert(RoleInterface $role)

Implements hook_ENTITY_TYPE_insert() for user_role entities.

File

core/modules/user/user.module, line 982
Enables the user registration and login system.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function user_user_role_insert(RoleInterface $role) {
  // Ignore the authenticated and anonymous roles or the role is being synced.
  if (in_array($role->id(), array(RoleInterface::AUTHENTICATED_ID, RoleInterface::ANONYMOUS_ID)) || $role->isSyncing()) {
    return;
  }
 
  $add_id = 'user_add_role_action.' . $role->id();
  if (!Action::load($add_id)) {
    $action = Action::create(array(
      'id' => $add_id,
      'type' => 'user',
      'label' => t('Add the @label role to the selected users', array('@label' => $role->label())),
      'configuration' => array(
        'rid' => $role->id(),
      ),
      'plugin' => 'user_add_role_action',
    ));
    $action->trustData()->save();
  }
  $remove_id = 'user_remove_role_action.' . $role->id();
  if (!Action::load($remove_id)) {
    $action = Action::create(array(
      'id' => $remove_id,
      'type' => 'user',
      'label' => t('Remove the @label role from the selected users', array('@label' => $role->label())),
      'configuration' => array(
        'rid' => $role->id(),
      ),
      'plugin' => 'user_remove_role_action',
    ));
    $action->trustData()->save();
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.