You are here

function fbconnect_form_alter in Facebook Connect 6

Same name and namespace in other branches
  1. 5 fbconnect.module \fbconnect_form_alter()
  2. 6.2 fbconnect.module \fbconnect_form_alter()

Impletementation of hook_form_alter.

File

./fbconnect.module, line 220

Code

function fbconnect_form_alter(&$form, $form_state, $form_id) {
  global $user;

  // if (in_array($form_id, array('user_profile_form', 'user_edit_form', 'user_register'))) {
  // variable to catch any content type edit form's name
  preg_match('/([a-z0-9_]+)_node_form$/', $form_id, $matches);
  $ctype = isset($matches[1]) ? $matches[1] : '';
  $ctypeformid = $ctype . '_node_form';
  if (isset($form['account'])) {
    $form['account']['mail']['#maxlength'] = 320;
  }
  switch ($form_id) {
    case 'user_login':
      if (@$_REQUEST['destination'] == 'fbconnect') {
        drupal_set_message(t('Please log in, in order to link your account with Facebook Connect'));
        $form['#submit'][] = 'fbconnect_redirect_submit';
      }

    // don't break here since we want to run the next user_login_block case too
    // Render fbconnect on login block.
    case 'user_login_block':
      if (@$_REQUEST['destination'] != 'fbconnect' && fbconnect_get_config()) {
        $form['fbconnect_button'] = array(
          '#type' => 'item',
          '#description' => t('Sign in using Facebook'),
          '#value' => fbconnect_render_button(),
          '#weight' => 1,
          '#id' => 'fbconnect_button',
        );
      }
      break;

    // Warning msg on user edit.
    case 'user_profile_form':
      if (variable_get('user_pictures', 0)) {
        $account = $form['_account']['#value'];
        if ($account->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_user_edit_submit';
        }
      }
      break;

    // Facebook feed checkbox on comment form.
    case 'comment_form':
      $fbuid = fbconnect_get_fbuid();
      if ($fbuid && _is_fbconnect_user($fbuid) == $user->uid && ($form['uid']['#value'] == 0 || $form['uid']['#value'] == $user->uid)) {
        $favicon = '<img src="http://wiki.developers.facebook.com/images/1/17/Connect_light_small_short.gif" />';
        $form['fbconnect_feed'] = array(
          '#type' => 'checkbox',
          '#title' => $favicon . t(' Publish To Facebook'),
          '#default_value' => 1,
          '#weight' => 0,
        );
        $form['#submit'][] = 'fbconnect_comment_feed_submit';
      }
      break;

    // admin settings for enabling/disabling the ability to publish to facebook, per node type
    case 'node_type_form':
      $form['fbconnect_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Facebook Connect'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['fbconnect_settings']['onoff'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow this content type to publish to facebook'),
        '#default_value' => variable_get('fbconnect_' . $form['#node_type']->type . '_onoff', 0),
      );
      $form['#submit'][] = 'fbconnect_node_type_form_save';
      break;

    // Facebook feed checkbox on node edit/create form.
    // only show this on the create new forms, not the edit forms
    case $ctypeformid:
      if ($form['nid']['#value'] == NULL && fbconnect_get_fbuid() && variable_get('fbconnect_' . $ctype . '_onoff', 0) === 1) {
        $favicon = '<img src="http://wiki.developers.facebook.com/images/1/17/Connect_light_small_short.gif" />';
        $form['fbconnect_feed'] = array(
          '#type' => 'checkbox',
          '#title' => $favicon . t(' Publish To Facebook'),
          '#default_value' => 1,
          '#weight' => 0,
        );
      }
      break;
  }
}