Form to configure a single role.
function user_admin_role($form, $form_state, $role) {
$form['role'] = array(
'#tree' => TRUE,
'#parents' => array(
'role',
),
);
$form['role']['name'] = array(
'#type' => 'textfield',
'#title' => t('Role name'),
'#default_value' => $role->name,
'#size' => 30,
'#required' => TRUE,
'#maxlength' => 64,
'#description' => t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'),
);
$form['role']['rid'] = array(
'#type' => 'machine_name',
'#default_value' => $role->rid,
'#required' => TRUE,
'#disabled' => !empty($role->rid),
'#size' => 30,
'#maxlength' => 64,
'#machine_name' => array(
'exists' => 'user_role_load',
'source' => array(
'role',
'name',
),
),
);
$form['role']['weight'] = array(
'#type' => 'value',
'#value' => $role->weight,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => !empty($role->rid) ? t('Save role') : t('Add role'),
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete role'),
'#access' => !empty($role->rid) && !in_array($role->rid, array(
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
)),
'#submit' => array(
'user_admin_role_delete_submit',
),
);
return $form;
}