1 user.admin.inc | user_admin_role($form, &$form_state, $role = NULL) |
Form to add or configure a single role.
See also
Related topics
File
- core/
modules/ user/ user.admin.inc, line 701 - 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['description'] = array(
'#type' => 'textarea',
'#rows' => 3,
'#title' => t('Description'),
'#default_value' => isset($role->description) ? $role->description : '',
'#description' => t('Summary of this role\'s purpose, shown on the role listing page and when assigning this role on user account forms.'),
);
$form['weight'] = array(
'#type' => 'value',
'#value' => empty($role->weight) ? 0 : $role->weight,
);
$form['actions'] = array('#type' => 'actions');
// Only show the 'Save and set permissions' button when creating a new role.
if (empty($role)) {
$form['actions']['continue'] = array(
'#type' => 'submit',
'#value' => t('Save and set permissions'),
);
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save role'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#href' => 'admin/config/people/roles',
'#title' => t('Cancel'),
'#options' => array('attributes' => array('class' => array('form-cancel'))),
);
return $form;
}