function bakery_form_alter in Bakery Single Sign-On System 6.2
Same name and namespace in other branches
- 8.2 bakery.module \bakery_form_alter()
- 6 bakery.module \bakery_form_alter()
- 7.4 bakery.module \bakery_form_alter()
- 7.2 bakery.module \bakery_form_alter()
- 7.3 bakery.module \bakery_form_alter()
Implementation of hook_form_alter().
Hide username and password options.
File
- ./
bakery.module, line 211
Code
function bakery_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_profile_form':
case 'user_edit_form':
if (!variable_get('bakery_is_master', 0) && !user_access('administer users')) {
$init_url = _bakery_init_field_url($form['_account']['#value']->init);
$index = key($form);
if (isset($form['account'])) {
drupal_set_message(t('You can change the name, mail, and password at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
)), 'status', FALSE);
$form['account']['#access'] = FALSE;
$form['account']['name']['#access'] = FALSE;
$form['account']['pass']['#access'] = FALSE;
$form['account']['mail']['#access'] = FALSE;
}
foreach (variable_get('bakery_supported_fields', array(
'mail' => 'mail',
'name' => 'name',
)) as $type => $value) {
if ($value) {
switch ($type) {
case 'mail':
case 'name':
break;
case 'picture':
if (isset($form['picture'])) {
$form['picture']['picture_delete']['#access'] = FALSE;
$form['picture']['picture_upload']['#access'] = FALSE;
$form['picture']['#description'] .= ' ' . t('You can change the image at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
));
}
break;
case 'language':
if (isset($form['locale'][$type])) {
$form['locale'][$type]['#disabled'] = TRUE;
$form['locale'][$type]['#description'] .= ' ' . t('You can change the language setting at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
));
}
break;
case 'signature':
if (isset($form['signature_settings'][$type])) {
$form['signature_settings'][$type]['#disabled'] = TRUE;
$form['signature_settings'][$type]['#description'] .= ' ' . t('You can change the signature at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
));
}
break;
default:
if (isset($form[$type])) {
$form[$type]['#disabled'] = TRUE;
}
if (isset($form[$type][$type])) {
$form[$type][$type]['#disabled'] = TRUE;
$form[$type][$type]['#description'] .= ' ' . t('You can change this setting at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
));
}
// profile fields
if ($form[$index]['#type'] == 'fieldset' && isset($form[$index][$type])) {
$form[$index][$type]['#disabled'] = TRUE;
$form[$index][$type]['#description'] .= ' ' . t('You can change this setting at <a href="!url">@master</a>.', array(
'!url' => check_url($init_url),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
));
}
break;
}
}
}
}
break;
case 'user_register':
// Provide register ability on the slave sites.
if (!variable_get('bakery_is_master', FALSE)) {
if (arg(0) == 'admin') {
// Admin create user form. Add a note about account synchronization.
$form['account']['bakery_help'] = array(
'#value' => t('<strong>Note:</strong> Only use this form to create accounts for users who exist on <a href="!url">@master</a> and not on this site. Be sure to use the exact same username and e-mail for the account here that they have on @master.', array(
'!url' => variable_get('bakery_master', 'http://drupal.org'),
'@master' => variable_get('bakery_master', 'http://drupal.org'),
)),
'#weight' => -100,
);
}
else {
// Anonymous user registration form.
// Populate fields if set from previous attempt.
if (isset($_SESSION['bakery']['register'])) {
$form['account']['name']['#default_value'] = $_SESSION['bakery']['register']['name'];
$form['account']['mail']['#default_value'] = $_SESSION['bakery']['register']['mail'];
unset($_SESSION['bakery']['register']);
}
// Replace the submit handler with our own.
$form['#submit'] = array(
'_bakery_register_submit',
);
}
}
break;
case 'user_pass':
// Slave sites need to make sure the local account exists, if the master
// account exists.
if (!variable_get('bakery_is_master', FALSE)) {
array_unshift($form['#validate'], '_bakery_pass_validate');
}
break;
case 'user_pass_reset':
// As part of the slave site registration we need to handle email
// validation and password reset.
if (!variable_get('bakery_is_master', FALSE)) {
// Set a submit handler for the psuedo-reset form.
$form['#submit'] = array(
'_bakery_reset_submit',
);
// Unset its custom action.
unset($form['#action']);
}
break;
case 'user_login_block':
case 'user_login':
// Provide login ability on the slave sites.
if (!variable_get('bakery_is_master', FALSE)) {
// Replace two validators from user module because they log the user in
// and test if account exists. We want to check if the account exists on
// the master instead.
$form['#validate'] = array_diff($form['#validate'], array(
'user_login_authenticate_validate',
'user_login_final_validate',
));
// Also replace the submit handler with our own to set a redirect cookie.
$form['#submit'] = array(
'_bakery_login_submit',
);
}
elseif (arg(0) == 'bakery') {
// If this is a master site with a login coming from the subsite
// replace two of the validators on the master's special Bakery login.
$form['#validate'] = array_diff($form['#validate'], array(
'user_login_authenticate_validate',
'user_login_final_validate',
));
}
break;
default:
break;
}
}