You are here

function fboauth_form_user_profile_form_alter in Facebook OAuth (FBOAuth) 7

Same name and namespace in other branches
  1. 6 fboauth.module \fboauth_form_user_profile_form_alter()
  2. 7.2 fboauth.module \fboauth_form_user_profile_form_alter()

Implements hook_form_FORM_ID_alter().

File

./fboauth.module, line 123

Code

function fboauth_form_user_profile_form_alter(&$form, &$form_state) {
  $uid = $form['#user']->uid;
  $fbid = fboauth_fbid_load($uid);
  $fboauth_form = array(
    '#type' => 'item',
    '#title' => t('Facebook connect'),
    '#markup' => theme('fboauth_user_form_connect', array(
      'uid' => $uid,
      'fbid' => $fbid,
    )),
  );

  // The account settings move around in this form.
  $account_form = isset($form['account']) ? $form['account'] : $form;

  // If a user has created/linked an account through a Facebook login, remove
  // the current password field until they set a password.
  // See http://drupal.org/node/1398782.
  if ($fbid && $form['#user']->pass == '') {
    if (empty($form_state['input'])) {
      drupal_set_message(t('Please set a password to secure your account details.'), 'warning', FALSE);
    }
    unset($account_form['current_pass']);
    $account_form['current_pass_required_values']['#value'] = array();
  }

  // Inject the Facebook options after the e-mail settings. No weights are on
  // these elements by default, so we have to put it in order.
  $temp_form = array();
  foreach (element_children($account_form) as $child) {
    $temp_form[$child] = $account_form[$child];
    if ($child == 'mail') {
      if (isset($temp_form[$child]['#weight'])) {
        $fboauth_form['#weight'] = $temp_form[$child]['#weight'];
      }
      $temp_form['fboauth'] = $fboauth_form;
    }
    unset($account_form[$child]);
  }
  $account_form += $temp_form;
  if (isset($form['account'])) {
    $form['account'] = $account_form;
  }
  else {
    $form = $account_form;
  }
}