You are here

function cas_roles_user_role_presave in CAS roles 7.2

Same name and namespace in other branches
  1. 7 cas_roles.module \cas_roles_user_role_presave()

Implements hook_user_role_presave().

File

./cas_roles.module, line 184
Allows user account and profile attributes to be automatically populated using tokens. Provides basic tokens for attributes returned by the CAS server.

Code

function cas_roles_user_role_presave($role) {

  // We have to use presave her because later the role ID is not known any more
  // because we don't know the old name otherwise,
  // this might potentially be a problem if another hook changes the name.
  $relations = variable_get('cas_roles_relations', array());
  $all_roles = user_roles(TRUE);

  // Set the new key and delete the old one.
  if (isset($role->rid)) {
    if (isset($all_roles[$role->rid]) && isset($relations[$all_roles[$role->rid]])) {

      // Only change if the name changed.
      if ($role->name != $all_roles[$role->rid]) {
        $relations[$role->name] = $relations[$all_roles[$role->rid]];
        unset($relations[$all_roles[$role->rid]]);
      }
    }
  }
  variable_set('cas_roles_relations', $relations);
}