function autoassignrole_admin_form in Auto Assign Role 6.2
Same name and namespace in other branches
- 6 autoassignrole-admin.inc \autoassignrole_admin_form()
Admin form handler.
1 string reference to 'autoassignrole_admin_form'
- autoassignrole_menu in ./
autoassignrole.module - Implementation of hook_menu().
File
- ./
autoassignrole-admin.inc, line 14 - The autoassignrole-admin.inc file
Code
function autoassignrole_admin_form() {
$form['autoassignrole_settings_auto'] = array(
'#type' => 'fieldset',
'#title' => t('Automatic Role Assignment'),
'#description' => t('Automatically assigned roles will be attached to accounts created through the administrative interface as well as normal new user registration according to the following settings.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['autoassignrole_settings_auto']['auto_active'] = array(
'#type' => 'radios',
'#title' => t('Automatic role assignment'),
'#default_value' => _autoassignrole_get_settings('auto_active'),
'#description' => t('Automatic role assignment occurs when the user first logins to the account. This happens without the users knowledge. Set to Enabled to allow this functionality or Disabled to not allow.'),
'#options' => array(
1 => t('Enabled'),
0 => t('Disabled'),
),
);
$form['autoassignrole_settings_auto']['auto_admin_active'] = array(
'#type' => 'radios',
'#title' => t('Automatic role assignment for admin created accounts'),
'#default_value' => _autoassignrole_get_settings('auto_admin_active'),
'#description' => t('Automatically assign roles if the user account is being created by an administrator.'),
'#options' => array(
1 => t('Enabled'),
0 => t('Disabled'),
),
);
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
if ($roles) {
$form['autoassignrole_settings_auto']['auto_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#default_value' => _autoassignrole_get_settings('auto_roles'),
'#description' => t('Check the specific Roles the user will automatically be assigned to when created by an administrator or through the new user registration process. The Authenticated User role is automatically assigned by Drupal core and can not be edited.'),
'#options' => $roles,
);
}
$form['autoassignrole_settings_page'] = array(
'#type' => 'fieldset',
'#title' => t('Assign from Path'),
'#description' => t('Assign user roles based on the path the user is creating the account from.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$default = '';
if ($nid = _autoassignrole_get_settings('node_user_register')) {
$node = db_fetch_object(db_query("SELECT nid, title FROM {node} WHERE nid = %d", $nid));
$default = check_plain($node->title) . " [nid:{$node->nid}]";
}
$form['autoassignrole_settings_page']['node_user_register'] = array(
'#type' => 'textfield',
'#title' => t('User Register Node'),
'#description' => t('This is a node that you want to use to replace the default user/register landing page. A common use would be to populate this node with a description and links to each of the other paths you define below. '),
'#maxlength' => 60,
'#autocomplete_path' => 'admin/user/autoassignrole/autocomplete/node',
'#default_value' => $default,
'#weight' => -1,
);
$result = db_query("SELECT rid, display, path, title, description, format, weight, menu, registration FROM {autoassignrole_page}");
$defaults = array();
while ($setting = db_fetch_object($result)) {
$defaults[$setting->rid] = array(
'display' => $setting->display,
'path' => $setting->path,
'title' => $setting->title,
'description' => $setting->description,
'format' => $setting->format,
'weight' => $setting->weight,
'menu' => $setting->menu,
'registration' => $setting->registration,
);
}
foreach ($roles as $k => $v) {
$active = isset($defaults[$k]['display']) ? 1 : 0;
$form['autoassignrole_settings_page'][$k] = array(
'#type' => 'fieldset',
'#title' => $v,
'#collapsible' => TRUE,
'#collapsed' => $active ? FALSE : TRUE,
);
$form['autoassignrole_settings_page'][$k]["path_active_{$k}"] = array(
'#type' => 'radios',
'#title' => check_plain($v) . ' ' . t('status'),
'#default_value' => $active,
'#description' => t('Enable or disable this role for path based role assignment'),
'#options' => array(
1 => t('Enabled'),
0 => t('Disabled'),
),
);
$form['autoassignrole_settings_page'][$k]["path_registration_{$k}"] = array(
'#type' => 'radios',
'#title' => t('Default Registration Page'),
'#default_value' => isset($defaults[$k]['registration']) ? $defaults[$k]['registration'] : 0,
'#description' => t('Should this path replace the default user/register path?'),
'#options' => array(
1 => t('Yes'),
0 => t('No'),
),
);
$form['autoassignrole_settings_page'][$k]["path_display_{$k}"] = array(
'#type' => 'radios',
'#title' => t('Display Method'),
'#default_value' => isset($defaults[$k]['display']) ? $defaults[$k]['display'] : 0,
'#description' => t('Menu Items are displayed as normal menu items. Tabs on registration pages display on the standard user/* pages. Pages with no navigation do not display in the menu and rely on you to provide a method for end users to reach them. For example, if you set this path as the default registration page and select Pages with no navigation, the default login block will have a link to your registration page but it will not show up in any menu.'),
'#options' => array(
0 => t('Menu Items'),
1 => t('Tabs on registration page'),
2 => t('Pages with no navigation'),
),
);
$form['autoassignrole_settings_page'][$k]["path_menu_{$k}"] = array(
'#type' => 'select',
'#title' => t('Menu'),
'#default_value' => isset($defaults[$k]['menu']) ? $defaults[$k]['menu'] : '',
'#description' => t('If this path is going to be displayed as a menu item which parent menu should it appear under? This setting will be ignored for all Display Methods except Menu Items.'),
'#options' => menu_get_menus(),
);
$form['autoassignrole_settings_page'][$k]["path_weight_{$k}"] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => isset($defaults[$k]['weight']) ? $defaults[$k]['weight'] : '0',
'#delta' => 10,
'#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
);
$form['autoassignrole_settings_page'][$k]["path_{$k}"] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#description' => t('The Drupal path for this role. This is a relative path based on your Drupal installation.'),
'#default_value' => isset($defaults[$k]['path']) ? $defaults[$k]['path'] : '',
'#size' => 60,
'#maxlength' => 128,
'#required' => FALSE,
);
$form['autoassignrole_settings_page'][$k]["path_title_{$k}"] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The title that will be displayed to users in menus, if applicable, and on the path landing page.'),
'#default_value' => isset($defaults[$k]['title']) ? $defaults[$k]['title'] : '',
'#size' => 60,
'#maxlength' => 128,
'#required' => FALSE,
);
$form['autoassignrole_settings_page'][$k]["path_description_{$k}"] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('The description displayed to the end user when they are selecting their role during registration. This description is filtered in a similar fashion to node body content.'),
'#default_value' => isset($defaults[$k]['description']) ? $defaults[$k]['description'] : '',
'#required' => FALSE,
);
$format = isset($defaults[$k]['format']) ? $defaults[$k]['format'] : FILTER_FORMAT_DEFAULT;
$form['autoassignrole_settings_page'][$k]["format"] = filter_form($format);
foreach ($form['autoassignrole_settings_page'][$k]["format"] as $key => $value) {
if (is_numeric($key) && isset($value['#parents'][0])) {
$form['autoassignrole_settings_page'][$k]["format"][$key]['#parents'][0] = "path_format_{$k}";
}
}
}
$form['autoassignrole_settings_user'] = array(
'#type' => 'fieldset',
'#title' => t('Allow User to Choose'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['autoassignrole_settings_user']['user_active'] = array(
'#type' => 'radios',
'#title' => t('User Role Assignment'),
'#default_value' => _autoassignrole_get_settings('user_active'),
'#description' => t('The end user will be allowed to select the following roles when they log in.'),
'#options' => array(
1 => t('Enabled'),
0 => t('Disabled'),
),
);
if ($roles) {
$form['autoassignrole_settings_user']['user_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#default_value' => _autoassignrole_get_settings('user_roles'),
'#options' => $roles,
);
}
$form['autoassignrole_settings_user']['selection']['user_multiple'] = array(
'#type' => 'radios',
'#title' => t('User Role Selection'),
'#default_value' => _autoassignrole_get_settings('user_multiple'),
'#description' => t('Should the end user be allowed to choose a single role or can they choose multiple roles?'),
'#options' => array(
0 => t('Single Role'),
1 => t('Multiple Roles'),
),
);
$form['autoassignrole_settings_user']['user_selection'] = array(
'#type' => 'radios',
'#title' => t('Selection Method'),
'#default_value' => _autoassignrole_get_settings('user_selection'),
'#description' => t('The type of form elements the end user will be presented with.'),
'#options' => array(
0 => t('Radio Buttons'),
1 => t('Selection Box'),
2 => t('Check Boxes'),
),
);
$form['autoassignrole_settings_user']['user_required'] = array(
'#type' => 'radios',
'#title' => t('Required'),
'#default_value' => _autoassignrole_get_settings('user_required'),
'#description' => t('Should the end user be required to choose a role?'),
'#options' => array(
0 => t('No'),
1 => t('Yes'),
),
);
$form['autoassignrole_settings_user']['user_sort'] = array(
'#type' => 'radios',
'#title' => t('Sorting'),
'#default_value' => _autoassignrole_get_settings('user_sort'),
'#description' => t('Default sort order of roles the user will see.'),
'#options' => array(
'SORT_ASC' => t('Ascending'),
'SORT_DESC' => t('Descending'),
),
);
$form['autoassignrole_settings_user']['user_fieldset_title'] = array(
'#type' => 'textfield',
'#title' => t('User Role Fieldset Title'),
'#description' => t('The title of the fieldset that contains role
options.'),
'#default_value' => _autoassignrole_get_settings('user_fieldset_title'),
'#size' => 60,
'#maxlength' => 128,
);
$form['autoassignrole_settings_user']['user_title'] = array(
'#type' => 'textfield',
'#title' => t('User Role Title'),
'#description' => t('The title of the field that contains the role options the end user sees during registration.'),
'#default_value' => _autoassignrole_get_settings('user_title'),
'#size' => 60,
'#maxlength' => 128,
'#required' => FALSE,
);
$form['autoassignrole_settings_user']['user_description'] = array(
'#type' => 'textarea',
'#title' => t('User Role Description'),
'#description' => t('The description displayed to the end user when they are selecting their role during registration.'),
'#default_value' => _autoassignrole_get_settings('user_description'),
'#required' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}