function role_delegation_roles_form_submit in Role Delegation 6
Same name and namespace in other branches
- 5 role_delegation.module \role_delegation_roles_form_submit()
- 7 role_delegation.module \role_delegation_roles_form_submit()
Saves the roles assigned to the account given in the form.
File
- ./
role_delegation.module, line 101 - This module allows site administrators to grant some roles the authority to assign selected roles to users, without them needing the 'administer access control' permission.
Code
function role_delegation_roles_form_submit($form, &$form_state) {
if (is_array($form_state['values']['roles']) && isset($form_state['values']['account']->uid)) {
$account = user_load(array(
'uid' => (int) $form_state['values']['account']->uid,
));
$myroles = array();
$rolenames = user_roles(TRUE);
foreach (array_keys(array_filter($form_state['values']['roles'])) as $rid) {
$myroles[$rid] = $rolenames[$rid];
}
user_save($account, array(
'roles' => $myroles,
));
// Delete the user's menu cache.
cache_clear_all($form_state['values']['account']->uid . ':', 'cache_menu', TRUE);
drupal_set_message(t('The roles have been updated.'));
}
}