You are here

function apply_for_role_form_alter in Apply for role 7

Same name and namespace in other branches
  1. 7.2 apply_for_role.module \apply_for_role_form_alter()

Implements hook_form_alter().

File

./apply_for_role.module, line 293
Allows users to apply for roles.

Code

function apply_for_role_form_alter(&$form, &$form_state, $form_id) {
  if (!($form_id == 'user_register_form')) {
    return;
  }

  // Admin created account aren't processed by the module.
  if (user_access('administer users')) {
    return;
  }
  elseif (variable_get('apply_for_role_register', 0)) {
    $filter_roles = array();
    foreach (variable_get('users_apply_roles', array()) as $rid => $role) {
      if ($rid > 2) {
        $filter_roles[$rid] = $role;
      }
    }
    if (count($filter_roles)) {
      $form['apply_for_role'] = array(
        '#type' => 'fieldset',
        '#title' => t('Apply for role'),
        '#collapsible' => FALSE,
      );
      if (variable_get('apply_for_role_multiple', 0) == 0 && variable_get('apply_for_role_register', 0) == 1) {
        $filter_roles[0] = t('--');
        ksort($filter_roles);
      }
      $form['apply_for_role']['rid'] = array(
        '#type' => variable_get('apply_for_role_multiple', 0) ? 'checkboxes' : 'select',
        '#title' => variable_get('apply_for_role_multiple', 0) ? t('Select a role or roles') : t('Select a role'),
        '#options' => $filter_roles,
        '#required' => variable_get('apply_for_role_register', 0) == 2 ? TRUE : FALSE,
      );
    }
  }
}