You are here

function signup_roles_form_alter in Signup 6

Same name and namespace in other branches
  1. 7 modules/signup_roles/signup_roles.module \signup_roles_form_alter()

Implementation of hook_form_alter().

File

modules/signup_roles/signup_roles.module, line 43
The Signup roles module allows administrators to configure a site so that it grants one or more roles to users when they sign up to nodes.

Code

function signup_roles_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'signup_settings_form') {

    // Only show them roles beyond the Authenticated.
    $roles = user_roles(TRUE);
    unset($roles[DRUPAL_AUTHENTICATED_RID]);
    $form['adv_settings']['signup_roles_grant'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Grant these roles when a signup is created'),
      '#default_value' => variable_get('signup_roles_grant', array()),
      '#options' => $roles,
      '#weight' => 6,
    );

    // If they don't have roles beyond authenticated, advise them on what to do.
    if (empty($roles)) {
      $form['adv_settings']['signup_roles_grant']['#description'] = t('Your site has no roles beyond authenticated, <a href="!create_url">create a role</a> to use this feature', array(
        '!create_url' => url('admin/user/roles'),
      ));
      $form['adv_settings']['signup_roles_grant']['#disabled'] = TRUE;
    }
  }
}