1.20.x user.admin.inc | user_admin_role($form, &$form_state, $role = NULL) |
Form to add or configure a single role.
See also
Related topics
File
- modules/
user/ user.admin.inc, line 629 - Admin page callbacks for the User module.
Code
function user_admin_role($form, &$form_state, $role = NULL) {
$form_state['role'] = $role;
if (empty($role)) {
backdrop_set_title('Add role');
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Role name'),
'#default_value' => empty($role->label) ? '' : $role->label,
'#size' => 30,
'#required' => TRUE,
'#maxlength' => 64,
'#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'),
);
$form['name'] = array(
'#type' => 'machine_name',
'#size' => 32,
'#maxlength' => 64,
'#default_value' => empty($role->name) ? '' : $role->name,
'#disabled' => empty($role->name) ? FALSE : TRUE,
'#machine_name' => array(
'exists' => 'user_role_load',
'source' => array('label'),
),
'#description' => t('A unique machine-readable name for this role. It must only contain lowercase letters, numbers, and underscores.'),
);
$form['weight'] = array(
'#type' => 'value',
'#value' => empty($role->weight) ? 0 : $role->weight,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save role'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#href' => 'admin/config/people/roles',
'#title' => t('Cancel'),
);
$form['actions']['cancel']['#options']['attributes']['class'][] = 'form-cancel';
return $form;
}