diff -Naur role_delegation/role_delegation.module role_delegation-new/role_delegation.module --- role_delegation/role_delegation.module 2009-06-29 11:01:13.000000000 -0400 +++ role_delegation-new/role_delegation.module 2009-07-15 15:51:43.000000000 -0400 @@ -173,60 +173,61 @@ if (user_access('administer permissions')) { return; } - // Split up roles based on whether they can be delegated or not. - $current_roles = (isset($form['#uid']) && $user = user_load(array('uid' => $form['#uid']))) ? $user->roles : array(); - $rids_default = array(); - $rids_preserve = array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID); - $roles_preserve = array('authenticated user'); - $roles_options = array(); - $roles = _role_delegation_roles(); - foreach ($roles as $rid => $role) { - if (user_access('assign all roles') || user_access(_role_delegation_make_perm($role))) { - if (array_key_exists($rid, $current_roles)) { - $rids_default[] = $rid; - } - $roles_options[$rid] = $role; - } - else { - if (array_key_exists($rid, $current_roles)) { - $rids_preserve[$rid] = $rid; - $roles_preserve[] = $role; - } - } - } - if (empty($roles_options)) { - // No role can be assigned. - return; - } - // Generate the form items. - $form['roles_preserve'] = array( - '#type' => 'value', - '#value' => $rids_preserve, - ); - $assign_item = array( - '#type' => 'checkboxes', - '#title' => t('Roles'), - '#description' => t('The user receives the combined permissions of the %roles role(s), and all roles selected here. ', array('%roles' => implode(', ', $roles_preserve))), - '#options' => $roles_options, - '#default_value' => $rids_default, - ); - if (isset($form['account'])) { - $form['account']['roles_assign'] = $assign_item; - } - else { - $form['roles_assign'] = $assign_item; - } } /** * Implementation of hook_user(). */ function role_delegation_user($op, &$edit, &$account, $category = NULL) { - if ($op != 'insert' && $op != 'submit') { - return; - } - if (!isset($edit['roles_assign'])) { - return; - } - $edit['roles'] = $edit['roles_preserve'] + array_filter($edit['roles_assign']); + switch ($op) { + case 'insert': + case 'submit': + if (!isset($edit['roles_assign'])) { + return; + } + $edit['roles'] = $edit['roles_preserve'] + array_filter($edit['roles_assign']); + break; + case 'form': + if ($category == 'account') { + // Split up roles based on whether they can be delegated or not. + $current_roles = $account->roles; + $rids_default = array(); + $rids_preserve = array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID); + $roles_preserve = array('authenticated user'); + $roles_options = array(); + $roles = _role_delegation_roles(); + foreach ($roles as $rid => $role) { + if (user_access('assign all roles') || user_access(_role_delegation_make_perm($role))) { + if (array_key_exists($rid, $current_roles)) { + $rids_default[] = $rid; + } + $roles_options[$rid] = $role; + } + else { + if (array_key_exists($rid, $current_roles)) { + $rids_preserve[$rid] = $rid; + $roles_preserve[] = $role; + } + } + } + if (empty($roles_options)) { + // No role can be assigned. + return; + } + // Generate the form items. + $form['roles_preserve'] = array( + '#type' => 'value', + '#value' => $rids_preserve, + ); + $assign_item = array( + '#type' => 'checkboxes', + '#title' => t('Roles'), + '#description' => t('The user receives the combined permissions of the %roles role(s), and all roles selected here. ', array('%roles' => implode(', ', $roles_preserve))), + '#options' => $roles_options, + '#default_value' => $rids_default, + ); + $form['roles_assign'] = $assign_item; + return $form; + } + } }