You are here

function user_user_role_insert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/user.module \user_user_role_insert()

Implements hook_ENTITY_TYPE_insert() for user_role entities.

File

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

Code

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 (!entity_load('action', $add_id)) {
    $action = entity_create('action', 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 (!entity_load('action', $remove_id)) {
    $action = entity_create('action', 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();
  }
}