You are here

function logintoboggan_form_user_profile_form_alter in LoginToboggan 7

Implement hook_form_user_profile_form_alter().

Related topics

File

./logintoboggan.module, line 158
LoginToboggan module

Code

function logintoboggan_form_user_profile_form_alter(&$form, &$form_state) {
  if ($form['#user_category'] == 'account') {
    $account = $form['#user'];
    $form['#validate'][] = 'logintoboggan_user_edit_validate';
    $id = logintoboggan_validating_id();

    // User is editing their own account settings, or user admin
    // is editing their account.
    if ($GLOBALS['user']->uid == $account->uid || user_access('administer users')) {

      // Display link to re-send validation e-mail.
      // Re-validate link appears if:
      //   1. Users can create their own password.
      //   2. User is still in the validating role.
      //   3. Users can create accounts without admin approval.
      //   4. The validating role is not the authorized user role.
      if (!variable_get('user_email_verification', TRUE) && array_key_exists($id, $account->roles) && variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS && $id > DRUPAL_AUTHENTICATED_RID) {
        $form['revalidate'] = array(
          '#type' => 'fieldset',
          '#title' => t('Account validation'),
          '#weight' => -10,
        );
        $form['revalidate']['revalidate_link'] = array(
          '#markup' => l(t('re-send validation e-mail'), 'toboggan/revalidate/' . $account->uid),
        );
      }
    }
    $pre_auth = !variable_get('user_email_verification', TRUE) && $id != DRUPAL_AUTHENTICATED_RID;
    $in_pre_auth_role = in_array($id, array_keys($account->roles));

    // Messages are only necessary for user admins, and aren't necessary if
    // there's no valid pre-auth role.
    if (user_access('administer users') && isset($form['account']['roles']) && $pre_auth) {

      // User is still in the pre-auth role, so let the admin know.
      if ($in_pre_auth_role) {

        // To reduce UI confusion, remove the disabled checkbox for the
        // authenticated user role.
        unset($form['account']['roles'][DRUPAL_AUTHENTICATED_RID]);

        // This form element is necessary as a placeholder for the user's
        // pre-auth setting on form load. It's used to compare against the
        // submitted form values to see if the pre-auth role has been unchecked.
        $form['logintoboggan_pre_auth_check'] = array(
          '#type' => 'hidden',
          '#value' => '1',
        );
        if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
          $form['account']['status']['#description'] = t('If this user was created using the "Immediate Login" feature of LoginToboggan, and they are also awaiting administrator approval on their account, you must remove them from the site\'s pre-authorized role in the "Roles" section below, or they will not receive authenticated user permissions!');
        }
        $form['account']['roles']['#description'] = t("The user is assigned LoginToboggan's pre-authorized role, and is not currently receiving authenticated user permissions.");
      }
      else {
        unset($form['account']['roles']['#options'][$id]);
      }
    }
  }
}