function twitter_post_form_alter in Twitter 6.5
Same name and namespace in other branches
- 6.3 twitter_post/twitter_post.module \twitter_post_form_alter()
- 6.4 twitter_post/twitter_post.module \twitter_post_form_alter()
- 7.3 twitter_post/twitter_post.module \twitter_post_form_alter()
- 7.4 twitter_post/twitter_post.module \twitter_post_form_alter()
- 7.5 twitter_post/twitter_post.module \twitter_post_form_alter()
Implements hook_form_alter().
File
- twitter_post/
twitter_post.module, line 46 - Hook implementations for twitter_post module.
Code
function twitter_post_form_alter(&$form, $form_state, $form_id) {
// If we haven't enabled Twitter posting on this node type, nothing to do here.
$allowed_types = variable_get('twitter_post_types', array());
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
$node = $form['#node'];
$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,
);
// Load the default values; use the values submitted by the form if this is
// a node preview.
$enabled = variable_get('twitter_post_default_value', 0);
if (!empty($node->nid) && !empty($node->status)) {
$enabled = variable_get('twitter_post_on_update', 0);
}
if (isset($form_state['values']['twitter']['post'])) {
$enabled = $form_state['values']['twitter']['post'];
}
$status = variable_get('twitter_post_default_format', 'New post: !title !url-alias');
if (isset($form_state['values']['twitter']['status'])) {
$status = $form_state['values']['twitter']['status'];
}
$form['twitter']['post'] = array(
'#type' => 'checkbox',
'#title' => t('Announce this post on Twitter'),
'#default_value' => $enabled,
'#id' => 'twitter-toggle',
);
$form['twitter'] += $twitter_form;
$form['twitter']['status']['#default_value'] = $status;
$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;
twitter_include_token_fields($form);
}
}