function role_delegation_roles_form in Role Delegation 6
Same name and namespace in other branches
- 5 role_delegation.module \role_delegation_roles_form()
- 7 role_delegation.module \role_delegation_roles_form()
Provides a form for assigning roles to the current user.
1 string reference to 'role_delegation_roles_form'
- role_delegation_menu in ./
role_delegation.module - Implementation of hook_menu().
File
- ./
role_delegation.module, line 56 - 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(&$form_state, $account) {
$form['roles'] = array(
'#type' => 'fieldset',
'#title' => t('Roles'),
'#tree' => TRUE,
);
// Provide a separate checkbox for each role but hide those the user has no authority over.
$roles = _role_delegation_roles();
$roles_preserve = array(
'authenticated user',
);
foreach ($roles as $rid => $role) {
if (!(user_access('assign all roles') || user_access(_role_delegation_make_perm($role)) || user_access('administer permissions'))) {
// Hide roles the user can't assign.
$form['roles'][$rid] = array(
'#type' => 'value',
'#value' => isset($account->roles[$rid]),
);
if (isset($account->roles[$rid])) {
$roles_preserve[] = $role;
}
}
else {
$form['roles'][$rid] = array(
'#type' => 'checkbox',
'#title' => check_plain($role),
'#default_value' => isset($account->roles[$rid]),
);
}
}
$form['roles']['#description'] = t('The user receives the combined permissions of the %roles role(s), and all roles selected here. ', array(
'%roles' => implode(', ', $roles_preserve),
));
$form['account'] = array(
'#type' => 'value',
'#value' => $account,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
drupal_set_title(check_plain($account->name));
return $form;
}