You are here

function fb_post_form_node_form_alter in Drupal for Facebook 7.4

Implements hook_form_BASE_FORM_ID_alter(). Implements hook_form_node_form_alter().

File

./fb_post.module, line 341

Code

function fb_post_form_node_form_alter(&$form, $form_state) {
  $node = $form['#node'];
  $enabled = variable_get('fb_post_enabled_' . $node->type, FALSE);
  if (!$enabled) {
    return;
  }
  $token = fb_get_admin_token();

  // Site-wide option to publish
  $form['fb_post_settings'] = array(
    '#type' => 'fieldset',
    '#access' => user_access(FB_POST_PERM_POST_NODE) || user_access(FB_POST_PERM_OVERRIDE_NODE),
    '#title' => t('Post to Facebook'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array(
        'fb-node-settings-form',
      ),
    ),
    '#attached' => array(),
  );
  if (user_access(FB_POST_PERM_POST_NODE)) {
    $form['fb_post_settings']['site-wide'] = array(
      '#type' => 'fieldset',
      '#title' => t('Default Settings'),
      '#description' => t(''),
    );
    if ($token) {
      $form['fb_post_settings']['site-wide']['fb_post_settings'] = _fb_post_node_settings_form(array(), $form_state, $node, $token);
    }
    else {
      $form['fb_post_settings']['site-wide']['fb'] = array(
        '#markup' => t('<a href=!url target=_blank>Configure settings</a> for site-wide publishing options.', array(
          '!url' => url(FB_POST_PATH_ADMIN),
        )),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
    }
  }

  // User-specific options
  $user_token = fb_user_token();
  if ($user_token && $user_token == $token) {

    // Don't show second settings when same token.
  }
  elseif (user_access(FB_POST_PERM_OVERRIDE_NODE)) {
    if ($fb_app = fb_get_app()) {
      $form['fb_post_settings']['fb_post_not_connected'] = array(
        '#markup' => t('<a href=!url target=_blank>Authorize the application</a> to see your publishing options.', array(
          '!url' => fb_client_auth_url(array(
            'scope' => 'publish_actions',
          )),
        )),
        '#prefix' => '<p class="fb_not_connected">',
        '#suffix' => '</p>',
      );
    }
    if ($user_token) {
      $form['fb_post_settings']['fb_post_user_settings'] = _fb_post_node_settings_form(array(), $form_state, $node, $user_token);
      $form['fb_post_settings']['fb_post_user_settings']['#prefix'] = '<div class="fb_connected">';
      $form['fb_post_settings']['fb_post_user_settings']['#suffix'] = '</div>';
    }
    else {
      $form['fb_post_settings']['fb_post_user_connected'] = array(
        '#markup' => t('Connected as !name.  Reload (or press preview button) to see posting options.', array(
          //'!name' => '<fb:name useyou=false linked=false uid=loggedinuser></fb:name>', // Old way XFBML
          '!name' => '<span class=fb_replace>!name</span>',
        )),
        '#prefix' => '<p class="fb_connected">',
        '#suffix' => '</p>',
      );
    }
  }
}