You are here

function twitter_signin_form_alter in Twitter 6.5

Same name and namespace in other branches
  1. 6.3 twitter_signin/twitter_signin.module \twitter_signin_form_alter()
  2. 6.4 twitter_signin/twitter_signin.module \twitter_signin_form_alter()
  3. 7.6 twitter_signin/twitter_signin.module \twitter_signin_form_alter()
  4. 7.3 twitter_signin/twitter_signin.module \twitter_signin_form_alter()
  5. 7.4 twitter_signin/twitter_signin.module \twitter_signin_form_alter()
  6. 7.5 twitter_signin/twitter_signin.module \twitter_signin_form_alter()

Implements hook_form_alter().

File

twitter_signin/twitter_signin.module, line 120
Hook implementations for twitter_signin submodule.

Code

function twitter_signin_form_alter(&$form, $form_state, $form_id) {

  // By default don't do anything when the site is in maintenance mode, but
  // allow this to be changed so that admins can still login.
  if (defined('MAINTENANCE_MODE') && !variable_get('twitter_signin_maintenance_mode', FALSE)) {
    return;
  }
  if ($form_id == 'twitter_oauth_callback' && isset($_SESSION['twitter_oauth']['signin'])) {
    $form['#submit'] = array_merge(array(
      'twitter_signin_oauth_callback_submit',
    ), $form['#submit']);
  }

  // Don't do anything else if the credentials haven't been set up yet.
  $key = variable_get('twitter_consumer_key', '');
  $secret = variable_get('twitter_consumer_secret', '');
  if (empty($key) || empty($secret)) {
    return;
  }

  // Login forms.
  if ($form_id == 'user_login' || $form_id == 'user_login_block') {
    if (variable_get('twitter_signin_login', TRUE)) {
      $items = array();
      $items[] = twitter_signin_button();
      $form['twitter_signin'] = array(
        '#value' => theme('item_list', $items),
      );
    }
  }
  elseif ($form_id == 'user_register' && isset($_SESSION['twitter']['values'])) {
    $form['name']['#default_value'] = $_SESSION['twitter']['values']['screen_name'];
    $form['auth_twitter'] = array(
      '#type' => 'hidden',
      '#value' => $_SESSION['twitter']['values']['user_id'],
    );
  }
}