You are here

function fbconnect_login_form_alter in Facebook Connect 8.2

Same name and namespace in other branches
  1. 7.2 fbconnect_login/fbconnect_login.module \fbconnect_login_form_alter()

Implements hook_form_alter().

File

fbconnect_login/fbconnect_login.module, line 263
Login functionality for Facebook Connect module

Code

function fbconnect_login_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['account'])) {
    $form['account']['mail']['#maxlength'] = 320;
  }
  switch ($form_id) {
    case 'user_register_form':

      // Add the FBConnect button to the user registration form, if enabled in
      // admin settings.
      if (variable_get('fbconnect_user_reg_display', TRUE)) {
        $weight = variable_get('fbconnect_user_reg_location', 'top') == 'top' ? -50 : 50;

        // create the FBConnect button
        $attr = array();
        if (variable_get('fbconnect_fast_reg', 0) && variable_get('fbconnect_reg_options', 0)) {
          $attr = array(
            'perms' => 'email',
          );
        }

        // Don't display if "fast reg" is enabled
        if (!variable_get('fbconnect_fast_reg', 0)) {
          $form['fbconnect_button'] = array(
            '#type' => 'item',
            '#description' => t('Sign in using Facebook'),
            '#markup' => fbconnect_login_render_button($attr),
            '#weight' => $weight,
          );
        }
      }
      break;
    case 'user_login':
      if (!empty($_GET['destination']) && $_GET['destination'] == 'fbconnect/link') {
        drupal_set_message(t('Please log in, in order to link your account with Facebook Connect'));
        $form['#submit'][] = 'fbconnect_login_redirect_submit';
      }

      // Check if there is a get paramater set(fbconnect=true)
      if (isset($_GET['fbconnect']) && $_GET['fbconnect'] == 'true') {

        // Add a function callback to call after user is logged in
        $form['#submit'][] = 'fbconnect_login_add_user_afterlogin_submit';
      }
      break;
    case 'user_profile_form':
      if (variable_get('user_pictures', 0) && isset($form['_account'])) {
        $account = $form['_account']['#value'];
        if ($account->data['fb_avatar'] && isset($form['picture'])) {
          $form['picture']['fb_avatar'] = array(
            '#value' => t('You are currently using your Facebook picture, if you delete or load a new picture, your Facebook picture will no longer be updated.'),
            '#weight' => 0,
          );
          $form['#submit'][] = 'fbconnect_login_user_edit_submit';
        }
      }
      break;
    case 'user_login_block':
      if ((empty($_GET['destination']) || $_GET['destination'] != 'fbconnect/link') && facebook_client()) {
        $form['fbconnect_button'] = array(
          '#type' => 'item',
          '#title' => t('Sign in using Facebook'),
          '#markup' => fbconnect_login_render_button(),
          '#weight' => -999,
          '#id' => 'fbconnect_button',
        );

        // Add a function callback to call after user is logged in
        $form['#submit'][] = 'fbconnect_login_add_user_afterlogin_submit';
      }
      break;
  }
}