You are here

function role_expire_user_insert in Role Expire 8

Same name and namespace in other branches
  1. 7 role_expire.module \role_expire_user_insert()
  2. 2.x role_expire.module \role_expire_user_insert()

Implements hook_user_insert().

File

./role_expire.module, line 221
Role Expire module.

Code

function role_expire_user_insert($account) {
  if (\Drupal::currentUser()
    ->hasPermission('administer role expire') || \Drupal::currentUser()
    ->hasPermission('administer users')) {

    // This adds default expiration to any new roles that have been given to the user.
    $new_roles = $account
      ->getRoles();

    // We have the new roles, loop over them and see whether we need to assign expiry to them.
    foreach ($new_roles as $role_id) {
      \Drupal::service('role_expire.api')
        ->processDefaultRoleDurationForUser($role_id, $account
        ->id());
    }
  }
}