Created
March 30, 2016 13:51
-
-
Save delmarr/b2b2564a4056d7e1cc6ae98162f42f11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Twitter Pull bean plugin. | |
*/ | |
class TwitterPullBean extends BeanPlugin { | |
/** | |
* Declares default block settings. | |
*/ | |
public function values() { | |
return array( | |
'settings' => array( | |
'twitkey' => FALSE, | |
'num_items' => 3, | |
), | |
); | |
} | |
/** | |
* Builds extra settings for the block edit form. | |
*/ | |
public function form($bean, $form, &$form_state) { | |
$form = array(); | |
$form['settings'] = array( | |
'#type' => 'fieldset', | |
'#tree' => 1, | |
'#title' => t('Options'), | |
); | |
$form['settings']['twitkey'] = array( | |
'#type' => 'textfield', | |
'#title' => t('Twitter Key'), | |
'#description' => t('Can be a username [prepended with @] a hashtag [prepended with #] or a search keyword [no prefix].'), | |
'#size' => 40, | |
'#maxlength' => 255, | |
'#default_value' => isset($bean->settings['twitkey']) ? $bean->settings['twitkey'] : '', | |
); | |
$form['settings']['num_items'] = array( | |
'#type' => 'select', | |
'#title' => t('Number of items'), | |
'#description' => t('Maximum number of tweets to pull from the Twitter result-set. The value of count is best thought of as a limit to the number of tweets to return because suspended or deleted content is removed after the count has been applied.'), | |
'#options' => drupal_map_assoc(range(1, 20)), | |
'#default_value' => isset($bean->settings['num_items']) ? $bean->settings['num_items'] : 3, | |
); | |
$form['settings']['retweet'] = array( | |
'#type' => 'checkbox', | |
'#title' => t('Display retweets'), | |
'#description' => t('Display retweets in result-set.'), | |
'#default_value' => TRUE, | |
); | |
return $form; | |
} | |
/** | |
* Implements hook_block_save(). | |
*/ | |
// public function status_block_save($delta = 0, $edit = array()) { | |
// variable_set('status_block_order', $edit['status_block_order']); | |
// variable_set('status_block_link', $edit['status_block_link']); | |
// variable_set('status_block_legend', $edit['status_block_legend']); | |
// } | |
/** | |
* Displays the bean. | |
*/ | |
public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { | |
if ($bean->settings['retweet'] == TRUE) { | |
$content['twitter_results']['#markup'] = twitter_pull_render($bean->settings['twitkey'], FALSE, $bean->settings['num_items'], NULL, FALSE, 1); | |
dpm('retweet'); | |
} | |
else { | |
dpm('just tweet tweet'); | |
$content['twitter_results']['#markup'] = twitter_pull_render($bean->settings['twitkey'], FALSE, $bean->settings['num_items']); | |
} | |
return $content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment