diff --git a/tweetbutton.info b/tweetbutton.info index 491a4b4..9bde0ae 100644 --- a/tweetbutton.info +++ b/tweetbutton.info @@ -2,4 +2,7 @@ name = Tweetbutton description = Add tweet button to your website without having to leave the page core = 7.x dependencies[] = token -configure = admin/config/services/tweetbutton \ No newline at end of file +configure = admin/config/services/tweetbutton + +files[] = tweetbutton.views.inc +files[] = tweetbutton_handler_field_tweet.inc diff --git a/tweetbutton.module b/tweetbutton.module index 95e09b8..8d8984f 100644 --- a/tweetbutton.module +++ b/tweetbutton.module @@ -192,4 +192,14 @@ function theme_tweetbutton_display($variables) { $link = '
'; return $link; -} \ No newline at end of file +} + + +/** + * Implementation of hook_views_api(). + */ +function tweetbutton_views_api() { + return array( + 'api' => '2.0', + ); +} diff --git a/tweetbutton.views.inc b/tweetbutton.views.inc new file mode 100644 index 0000000..fa84f16 --- /dev/null +++ b/tweetbutton.views.inc @@ -0,0 +1,43 @@ + array(), + ); + + $data['tweetbutton']['tweetbutton'] = array( + 'group' => t('tweet button'), + 'field' => array( + 'title' => t('Tweet Button'), + 'help' => t('Tweet button for this node.'), + 'handler' => 'tweetbutton_handler_field_tweet', + ), + ); + + return $data; +} + + +/** + * Implements of hook_views_handlers(). + */ +function tweetbutton_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'tweetbutton'), + ), + 'handlers' => array( + 'tweetbutton_handler_field_tweet' => array( + 'parent' => 'views_handler_field_node', + ), + ), + ); +} diff --git a/tweetbutton_handler_field_tweet.inc b/tweetbutton_handler_field_tweet.inc new file mode 100644 index 0000000..5b8626d --- /dev/null +++ b/tweetbutton_handler_field_tweet.inc @@ -0,0 +1,67 @@ +ensure_my_table(); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['layout'] = array('default' => 'none'); + $options['text'] = array('default' => '[node:title]'); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['layout'] = array( + '#type' => 'select', + '#title' => t('Layout style'), + '#default_value' => $this->options['layout'], + '#description' => t('Set the layout for your tweet button'), + '#options' => array('vertical' => 'Vertical Count', 'horizontal' => 'Horizontal Count', 'none' => 'No Count'), + ); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Tweet Text'), + '#default_value' => $this->options['text'], + '#description' => t('Recommend a text for the tweet.'), + ); + $form['tokens'] = array( + '#token_types' => array('node'), + '#theme' => 'token_tree', + ); + + // Remove irrelevant controls / settings. + unset($form['empty']); + unset($form['empty_zero']); + unset($form['hide_empty']); + unset($form['link_to_node']); + } + + function render($values) { + $nid = $values->nid; + $node = node_load($nid); + $url = url("node/$nid", array('absolute' => TRUE)); + $tweet_button = theme_tweetbutton_display(array( + 'object' => $node, + 'options' => array( + 'url' => $url, + 'type' => $this->options['layout'], + 'text' => $this->options['text'], + ), + )); + return $tweet_button; + } +}