You are here

function twitter_post_form_alter in Twitter 7.4

Same name and namespace in other branches
  1. 6.5 twitter_post/twitter_post.module \twitter_post_form_alter()
  2. 6.3 twitter_post/twitter_post.module \twitter_post_form_alter()
  3. 6.4 twitter_post/twitter_post.module \twitter_post_form_alter()
  4. 7.3 twitter_post/twitter_post.module \twitter_post_form_alter()
  5. 7.5 twitter_post/twitter_post.module \twitter_post_form_alter()

Implements hook_form_alter().

File

twitter_post/twitter_post.module, line 39
Main hooks for twitter post module

Code

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

  // Alter any node forms.
  if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {

    // If we haven't enabled Twitter posting on this node type, nothing to do
    // here.
    $type = $form['#node']->type;
    $allowed_types = variable_get('twitter_post_types', array(
      'story' => 'story',
      'blog' => 'blog',
    ));
    if (empty($allowed_types[$type])) {
      return;
    }
    module_load_include('inc', 'twitter');
    $twitter_form = twitter_post_form();
    if (!$twitter_form) {
      return;
    }
    $form['twitter'] = array(
      '#type' => 'fieldset',
      '#group' => 'additional_settings',
      '#title' => t('Post to twitter.com'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
    );
    $form['twitter']['post'] = array(
      '#type' => 'checkbox',
      '#title' => t('Announce this post on Twitter'),
      '#default_value' => empty($form['nid']['#value']),
      '#id' => 'twitter-toggle',
    );
    $form['twitter'] += $twitter_form;
    $form['twitter']['status']['#default_value'] = variable_get('twitter_post_default_format', 'New post: !title !url-alias');
    $form['twitter']['status']['#description'] = t('The given text will be posted to twitter.com. You can use !url, !url-alias, !tinyurl, !title and !user as replacement text.');
    $form['twitter']['status']['#maxlength'] = 150;
  }
}