diff --git a/roleassign.admin.inc b/roleassign.admin.inc index c33329b..fe60eef 100644 --- a/roleassign.admin.inc +++ b/roleassign.admin.inc @@ -73,7 +73,7 @@ function _roleassign_form_alter(array &$form, array &$form_state, $form_id) { $sticky_roles = array_intersect_key($roles, $sticky_roles); // Store sticky roles for later use in roleassign_user_presave(). - _roleassign_sticky_roles($sticky_roles); + $form['sticky_roles'] = array('#type' => 'value', '#value' => $sticky_roles); // Make a string of all sticky roles. $sticky_roles[DRUPAL_AUTHENTICATED_RID] = $roles[DRUPAL_AUTHENTICATED_RID]; @@ -137,9 +137,16 @@ function _roleassign_user_presave(array &$edit, $account, $category) { form_set_error('category', t("Detected malicious attempt to alter user's roles.")); } - // On submit, copy sticky and assigned roles from 'roleassign_roles' - // to 'roles'. - $edit['roles'] = array_filter(_roleassign_sticky_roles() + $edit['roleassign_roles']); + // Assign the roles the user already had as well as the selected roles + $edit['roles'] = array(); + foreach (array('sticky_roles', 'roleassign_roles') as $key) { + foreach ($edit[$key] as $rid => $value) { + if ($value) { + $edit['roles'][$rid] = $rid; + } + } + } + unset($edit['roleassign_roles']); } @@ -220,21 +227,6 @@ function _roleassign_assignable_roles(array $roles) { } /** - * Store and retrive sticky roles. - * - * @param array|null $new_sticky_roles - * - * @return array - */ -function _roleassign_sticky_roles($new_sticky_roles = NULL) { - static $sticky_roles = array(); - if (isset($new_sticky_roles)) { - $sticky_roles = $new_sticky_roles; - } - return $sticky_roles; -} - -/** * Really implements hook_help(). * * Returns various help texts.