You are here

function autoassignrole_user_settings in Auto Assign Role 7

Same name and namespace in other branches
  1. 7.2 autoassignrole.admin.inc \autoassignrole_user_settings()

Form builder; The settings form for user selectable role assignment.

See also

system_settings_form()

1 string reference to 'autoassignrole_user_settings'
autoassignrole_menu in ./autoassignrole.module
Implements hook_menu().

File

./autoassignrole.admin.inc, line 87
Administrative functionality for auto assign role.

Code

function autoassignrole_user_settings() {
  global $language;
  $form['autoassignrole_user_active'] = array(
    '#type' => 'radios',
    '#title' => t('User role assignment'),
    '#default_value' => variable_get('autoassignrole_user_active', 0),
    '#description' => t('Toggles allowing end users to select roles when creating their accounts.'),
    '#options' => array(
      1 => t('Enabled'),
      0 => t('Disabled'),
    ),
  );

  // We can disregard the authenticated user role since it is assigned to each
  // user by Drupal.
  $roles = user_roles(TRUE);
  unset($roles[DRUPAL_AUTHENTICATED_RID]);
  if ($roles) {
    $form['autoassignrole_user_roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Roles'),
      '#default_value' => variable_get('autoassignrole_user_roles', array()),
      '#description' => t('Check the specific roles the user will have the option of choosing. The Authenticated User role is automatically assigned by Drupal core and can not be edited.'),
      '#options' => $roles,
      '#states' => array(
        'visible' => array(
          ':input[name="autoassignrole_user_active"]' => array(
            'value' => 1,
          ),
        ),
      ),
    );
  }
  $form['autoassignrole_user_multiple'] = array(
    '#type' => 'radios',
    '#title' => t('User role selection'),
    '#default_value' => variable_get('autoassignrole_user_multiple', 0),
    '#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'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['autoassignrole_user_selection'] = array(
    '#type' => 'radios',
    '#title' => t('Selection method'),
    '#default_value' => variable_get('autoassignrole_user_selection', AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX),
    '#description' => t('The type of form elements the end user will be presented with.'),
    '#options' => array(
      AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX => t('Radio Buttons/Checkboxes'),
      AUTOASSIGNROLE_ELEMENT_SELECT => t('Selection Box'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['autoassignrole_user_required'] = array(
    '#type' => 'radios',
    '#title' => t('Required'),
    '#default_value' => variable_get('autoassignrole_user_required', 0),
    '#description' => t('Should the end user be required to choose a role?'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['autoassignrole_user_sort'] = array(
    '#type' => 'radios',
    '#title' => t('Sorting'),
    '#default_value' => variable_get('autoassignrole_user_sort', 'SORT_ASC'),
    '#description' => t('Default sort order of roles the user will see.'),
    '#options' => array(
      'SORT_ASC' => t('Ascending'),
      'SORT_DESC' => t('Descending'),
      'SORT_WEIGHT' => t('Weight of field'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );

  // Set the user description filter format.
  $autoassignrole_user_description = _autoassignrole_get_user_description();
  $form['autoassignrole_user_description'] = array(
    '#type' => 'text_format',
    '#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_user_description['value'],
    '#required' => FALSE,
    '#format' => $autoassignrole_user_description['format'],
    '#prefix' => '<div id="autoassignrole_user_description_wrapper">',
    '#suffix' => '</div>',
  );
  $form['autoassignrole_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' => variable_get('autoassignrole_user_fieldset_title', t('User Roles')),
    '#size' => 60,
    '#maxlength' => 128,
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['autoassignrole_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' => variable_get('autoassignrole_user_title', t('Role')),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['autoassignrole_user_fieldset_weight'] = array(
    '#type' => 'textfield',
    '#title' => t('User Role Fieldset weight'),
    '#description' => t('The weight of the fieldset that contains role options.') . '<br>' . t('To display this fieldset on top of the form, please specify weight less than -10. For Ex. -30.') . '<br>' . t('To display at the bottom of the form, please specify weight greater than 15.') . '<br>' . t('If the field is not appearing at desired position, please increase or decrease the weight that you have specified.'),
    '#number_type' => 'integer',
    '#field_name' => 'autoassignrole_user_fieldset_weight',
    '#element_validate' => array(
      'number_field_widget_validate',
    ),
    '#size' => 10,
    '#maxlength' => 10,
    '#field_parents' => array(),
    '#language' => $language->language,
    '#default_value' => variable_get('autoassignrole_user_fieldset_weight', 0),
    '#states' => array(
      'visible' => array(
        ':input[name="autoassignrole_user_active"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  return system_settings_form($form);
}