function logintoboggan_form_alter in LoginToboggan 5
Same name and namespace in other branches
- 8 logintoboggan.module \logintoboggan_form_alter()
- 6 logintoboggan.module \logintoboggan_form_alter()
- 7 logintoboggan.module \logintoboggan_form_alter()
Implementation of hook_form_alter()
Related topics
File
- ./
logintoboggan.module, line 107 - Logintoboggan Module
Code
function logintoboggan_form_alter($form_id, &$form) {
switch ($form_id) {
case 'block_admin_configure':
if ($form['module']['#value'] == 'user' && $form['delta']['#value'] == 0) {
$form['#submit'] += array(
'logintoboggan_user_block_admin_configure_submit' => array(
$form,
),
);
$form['block_settings']['title']['#description'] .= '<div id="logintoboggan-block-title-description">' . t('<strong>Note:</strong> Logintoboggan module is installed. If you are using one of the custom login block types below, it is recommended that you set this to <em><none></em>.') . '</div>';
$form['block_settings']['toboggan_block_type'] = array(
'#type' => 'radios',
'#title' => t('Block type'),
'#default_value' => variable_get('toboggan_block_type', 1),
'#options' => array(
t('Standard'),
t('Link'),
t('Collapsible form'),
),
'#description' => t("'Standard' is a standard login block, 'Link' is a login link that returns the user to the original page after logging in, 'Collapsible form' is a javascript collaspible login form."),
);
$form['block_settings']['toboggan_block_msg'] = array(
'#type' => 'textarea',
'#title' => t('Set a custom message to appear at the top of the login block'),
'#default_value' => variable_get('toboggan_block_msg', ''),
);
}
break;
case 'system_modules':
$form['#validate']['logintoboggan_site_403_validate'] = array();
break;
case 'logintoboggan_main_settings':
$form['#submit'] += array(
'logintoboggan_flip_user_email_verification' => array(),
);
break;
case 'user_edit':
$form['#validate'] += array(
'logintoboggan_user_edit_validate' => array(),
);
$account = $form['_account']['#value'];
$id = logintoboggan_validating_id();
$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) {
if (variable_get('user_register', 1) == 2) {
$form['account']['status']['#description'] = t('If this user was created using the "Immediate Login" feature of LoginToboggan, and they are also awaiting adminstrator 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]);
}
}
break;
case 'user_login':
case 'user_login_block':
// Grab the message from settings for display at the top of the login block.
if ($login_msg = variable_get('toboggan_block_msg', '')) {
$form['message'] = array(
'#value' => filter_xss_admin($login_msg),
'#weight' => -50,
);
}
$form['name']['#attributes']['tabindex'] = '1';
$form['pass']['#attributes']['tabindex'] = '2';
$form['submit']['#attributes']['tabindex'] = '3';
if (variable_get('login_with_mail', 0)) {
$form['#validate'] = array(
'logintoboggan_user_login_validate' => array(),
) + $form['#validate'];
// Use theme functions to print the username field's textual labels.
$form['name']['#title'] = theme('lt_username_title', $form_id);
$form['name']['#description'] = theme('lt_username_description', $form_id);
// Use theme functions to print the password field's textual labels.
$form['pass']['#title'] = theme('lt_password_title', $form_id);
$form['pass']['#description'] = theme('lt_password_description', $form_id);
}
if ($GLOBALS['logintoboggan_denied'] == TRUE) {
logintoboggan_destination();
}
if ($form_id == 'user_login_block') {
$block_type = variable_get('toboggan_block_type', 1);
if ($block_type == 1) {
$form = array(
'#value' => l(theme('lt_login_link'), 'user/login', array(), drupal_get_destination()),
);
}
elseif ($block_type == 2) {
$form = _logintoboggan_toggleboggan($form);
}
}
break;
case 'user_register':
// Admin created accounts are only validated by the module.
if (user_access('administer users')) {
$form['#validate'] += array(
'logintoboggan_user_register_validate' => array(),
);
break;
}
$mail = variable_get('email_reg_confirm', 0);
$pass = !variable_get('user_email_verification', TRUE);
// Replace core's registration function with LT's registration function.
// Put the LT submit handler first, so other submit handlers have a valid
// user to work with upon registration.
unset($form['#submit']['user_register_submit']);
$form['#submit'] = array(
'logintoboggan_user_register_submit' => array(),
) + $form['#submit'];
if ($mail || $pass) {
$form['#validate'] += array(
'logintoboggan_user_register_validate' => array(),
);
//Display a confirm e-mail address box if option is enabled.
if ($mail) {
// Make sure user help is at the top of the form.
$form['user_registration_help']['#weight'] = -100;
$form['conf_mail'] = array(
'#type' => 'textfield',
'#title' => t('Confirm e-mail address'),
'#weight' => -28,
'#maxlength' => 64,
'#description' => t('Please re-type your e-mail address to confirm it is accurate.'),
'#required' => TRUE,
);
// Weight things properly so that the order is name, mail, conf_mail, then pass
if (isset($form['account'])) {
$form['account']['#weight'] = -50;
// Make sure account form group is at the top of the display.
$form['account']['name']['#weight'] = -30;
$form['account']['mail']['#weight'] = -29;
$form['account']['conf_mail'] = $form['conf_mail'];
unset($form['conf_mail']);
$form['account']['conf_mail']['#weight'] = -28;
}
else {
$form['name']['#weight'] = -30;
$form['mail']['#weight'] = -29;
}
}
if ($pass) {
$min_pass = variable_get('toboggan_min_pass_length', 0);
$length = $min_pass ? t('between !min and', array(
'!min' => $min_pass,
)) : t('no more than');
$description = t('Please choose a password for your account; it must be !length 30 characters.', array(
'!length' => $length,
));
if (isset($form['account'])) {
$form['account']['pass']['#description'] = $description;
}
else {
$form['pass']['#description'] = $description;
}
}
}
break;
// Unset the ability to add the pre-auth role in the user admin interface.
case 'user_admin_account':
// Test here for a valid pre-auth -- we only remove this role if one exists.
$id = logintoboggan_validating_id();
$pre_auth = !variable_get('user_email_verification', TRUE) && $id != DRUPAL_AUTHENTICATED_RID;
$add = t('Add a role to the selected users');
if ($pre_auth && isset($form['options']['operation']['#options'][$add]["add_role-{$id}"])) {
unset($form['options']['operation']['#options'][$add]["add_role-{$id}"]);
}
break;
// Password resets count as validating an email address, so remove the user
// from the pre-auth role if they are still in it.
case 'user_pass_reset':
// We only want to run this code when the user first hits the reset login
// form.
if (arg(5) != 'login' && ($uid = (int) arg(2))) {
if ($account = user_load(array(
'uid' => $uid,
))) {
$id = logintoboggan_validating_id();
$in_pre_auth_role = in_array($id, array_keys($account->roles));
if ($in_pre_auth_role) {
_logintoboggan_process_validation($account);
drupal_set_message(t('You have successfully validated your e-mail address.'));
}
}
}
break;
}
}