You are here

function role_watchdog_user_save in Role Watchdog 7

Same name and namespace in other branches
  1. 6.2 role_watchdog.module \role_watchdog_user_save()
  2. 6 role_watchdog.module \role_watchdog_user_save()
  3. 7.2 role_watchdog.module \role_watchdog_user_save()

Process role add/remove.

1 call to role_watchdog_user_save()
role_watchdog_user_presave in ./role_watchdog.module
Implements hook_user_presave().

File

./role_watchdog.module, line 160
Logs changes to user roles.

Code

function role_watchdog_user_save($uid, &$form, $account) {

  // Incoming format: array([2] => authenticated user, [3] => test role,)
  $old_roles = _role_watchdog_user_roles_cache($account->uid);
  unset($old_roles[DRUPAL_AUTHENTICATED_RID]);

  // No built-in roles.
  if (!empty($old_roles)) {
    $old_roles = array_flip($old_roles);
  }

  // Outgoing format: array([test role] => 3,)
  // Incoming format: array([3] => 3, [2] => 1,)
  $new_roles = $form['roles'];
  unset($new_roles[DRUPAL_AUTHENTICATED_RID]);

  // No built-in roles.
  if (!empty($new_roles)) {
    $new_roles = array_flip($new_roles);
    unset($new_roles[0]);
  }

  // Outgoing format: array([3] => 3,)
  return _role_watchdog_process_role_changes($account, $new_roles, $old_roles);
}