You are here

function twitter_post_form_alter in Twitter 7.5

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.4 twitter_post/twitter_post.module \twitter_post_form_alter()

Implements hook_form_alter().

File

twitter_post/twitter_post.module, line 88
Hook implementations for twitter_post module.

Code

function twitter_post_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
    $node = $form['#node'];

    // Fail early if Twitter posting hasn't been on this node type.
    $allowed_types = variable_get('twitter_post_types', array());
    if (empty($allowed_types[$node->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'),
      '#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. Note that if a URL is being included, the maximum length of the rest of the tweet is 117 characters.');
    $form['twitter']['status']['#maxlength'] = 150;

    // Check the correct option based upon whether the node is published or not.
    $default = variable_get('twitter_post_default_value', 0);
    if (!empty($node->nid) && !empty($node->status)) {
      $default = variable_get('twitter_post_on_update', 0);
    }
    $form['twitter']['post']['#default_value'] = $default;

    // Only show the message field and account selector when the "Post" checkbox
    // is checked.
    $form['twitter']['status']['#states'] = array(
      'visible' => array(
        ':input[name="twitter[post]"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
    if ($form['twitter']['account']['#type'] == 'select') {
      $form['twitter']['account']['#states'] = $form['twitter']['status']['#states'];
    }
  }
}