function user_user_role_insert

Implements hook_user_role_insert().

File

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

Code

function user_user_role_insert(RoleInterface $role) {

  // Ignore the authenticated and anonymous roles.
  if (in_array($role
    ->id(), array(
    DRUPAL_AUTHENTICATED_RID,
    DRUPAL_ANONYMOUS_RID,
  ))) {
    return;
  }
  $action = entity_create('action', array(
    'id' => 'user_add_role_action.' . $role
      ->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
    ->save();
  $action = entity_create('action', array(
    'id' => 'user_remove_role_action.' . $role
      ->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
    ->save();
}