function fb_user_form_alter in Drupal for Facebook 6.3
Same name and namespace in other branches
- 5.2 fb_user.module \fb_user_form_alter()
- 5 fb_user.module \fb_user_form_alter()
- 6.2 fb_user.module \fb_user_form_alter()
- 7.3 fb_user.module \fb_user_form_alter()
Implements hook_form_alter().
File
- ./
fb_user.module, line 501 - This module manages relations between local Drupal user accounts and their accounts on facebook.com.
Code
function fb_user_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['fb_app_data'])) {
// Add our settings to the fb_app edit form.
module_load_include('inc', 'fb_user', 'fb_user.admin');
fb_user_admin_form_alter($form, $form_state, $form_id);
}
elseif ($form_id == 'user_edit' && ($app = $form['#fb_app'])) {
// Disable buttons on user/edit/app pages, nothing to submit
unset($form['submit']);
unset($form['delete']);
}
elseif ($form_id == 'user_profile_form') {
// On user/edit, hide proxied email
if (isset($form['account']) && isset($form['account']['mail'])) {
$account = $form['_account']['#value'];
if (isset($account->fb_user_proxied_mail) && $form['account']['mail']['#default_value'] == $account->fb_user_proxied_mail) {
unset($form['account']['mail']['#default_value']);
}
}
}
// Add name and email to some forms.
if (isset($GLOBALS['_fb'])) {
$fb = $GLOBALS['_fb'];
if (!$GLOBALS['user']->uid && ($form_id == 'user_register' && variable_get(FB_USER_VAR_ALTER_REGISTER, TRUE) || $form_id == 'user_login' && variable_get(FB_USER_VAR_ALTER_LOGIN, TRUE) || $form_id == 'user_login_block' && variable_get(FB_USER_VAR_ALTER_LOGIN_BLOCK, TRUE))) {
// Add a facebook connect button or profile pic to the form.
$fb_button = theme('fb_login_button', t(_fb_user_button_text($form_id)), array(
'form_id' => $form_id,
));
$form['fb_user'] = array(
'#fb_user' => NULL,
'connected' => array(
'#prefix' => '<div class=fb_connected>',
'#suffix' => '</div>',
'picture' => array(
'#value' => '<fb:profile-pic uid="loggedinuser" linked="false" facebook-logo="true"></fb:profile-pic>',
'#type' => 'markup',
'#prefix' => '<div class="fb_user_picture">',
'#suffix' => '</div>',
),
'text' => array(
'#type' => 'markup',
'#value' => t('!name, after <a href="!login_url">login</a> or <a href="!register_url">registration</a> your account will be connected.', array(
'!name' => '<fb:name uid=loggedinuser useyou=false linked=false></fb:name>',
'!login_url' => url('user/login'),
'!register_url' => url('user/register'),
)),
),
),
'loginbutton' => array(
'#value' => $fb_button,
'#type' => 'markup',
'#prefix' => '<div class="fb_user-login-button-wrapper fb_not_connected">',
'#suffix' => '</div>',
),
'#weight' => -1,
);
// @TODO confirm fb session before sharing sensitive data!
if ($fbu = fb_facebook_user($fb)) {
// Include $fb_user in form, so other modules can custom form_alter.
$data = _fb_user_facebook_data($fb);
$form['fb_user']['#fb_user'] = $data;
if ($form_id == 'user_register') {
if ($data) {
// Provide defaults for name and email.
if (isset($form['name']) && !$form['name']['#default_value']) {
// @TODO - ensure name is unique to Drupal.
$form['name']['#default_value'] = $data['name'];
}
elseif (isset($form['account']) && isset($form['account']['name']) && !$form['account']['name']['#default_value']) {
// @TODO - ensure name is unique to Drupal.
$form['account']['name']['#default_value'] = $data['name'];
}
if (isset($form['mail']) && !$form['mail']['#default_value']) {
$form['mail']['#default_value'] = $data['email'];
}
elseif (isset($form['account']['mail']) && isset($form['account']['mail']) && !$form['account']['mail']['#default_value']) {
$form['account']['mail']['#default_value'] = $data['email'];
}
}
}
}
}
elseif ($form_id == 'contact_mail_page' && variable_get(FB_USER_VAR_ALTER_CONTACT, TRUE)) {
if ($data = _fb_user_facebook_data($fb)) {
if (!$form['name']['#default_value'] || strpos($form['name']['#default_value'], '@facebook')) {
$form['name']['#default_value'] = $data['name'];
}
if (!$form['mail']['#default_value']) {
$form['mail']['#default_value'] = $data['email'];
}
}
}
}
}