After reading a lot of posts here about that issue i quickly implemented hook block (because im not into custom hacking into my templates and stuff). It may not be the best solution but i let you decide.

I could not really find out what the: theme_tweetbutton_display($entity, $options = array()
expects as $entity as you could input a whole node via node_load(1) or just an url as i did. some inline doc would be nice on what to pass this function.


/**
* Implementation of hook_block()
*/

function tweetbutton_block($op='list', $delta=0, $edit=array()) {

  global $base_url;

  switch ($op) {
  
  case 'list':
   $blocks[0]['info'] = t('Tweet Button'); //Blockname on Block Page
   return $blocks;

  case 'view':   
   $blocks['subject'] = t('Tweet Button'); //Title of Block
   $blocks['content'] = theme('tweetbutton_display', NULL, array('url' => $base_url . base_path() . $_GET['q'], 'text' => drupal_get_title() ));
   return $blocks;
   
   
  case 'configure':
     return $form;

  case 'save':
    
  }
    
}
Files: 

Comments

michaelfillier’s picture

I implemented blocks in a recent site. I created a block for each display mode. The setup uses aliased urls, not sure if there will be any conflict without it.

I attached a patch (first one so let me know if it works fine)

/**
 * Implementation of hook_block
 */
function tweetbutton_block($op = 'list', $delta = 0, $edit = array()){
  $url = url($_GET['q'], array('absolute' => TRUE, 'alias' => $aliased ));
  $attributes = array (
    'text' => drupal_get_title(),
    'url' => $url
  );
  switch ($op) {
    case 'list' :
      $blocks['tweetbutton_vertical'] = array(
        'info' => t('Tweet Button - Vertical'), 
      );
      $blocks['tweetbutton_horizontal'] = array(
        'info' => t('Tweet Button - Horizontal'), 
      );
      $blocks['tweetbutton_none'] = array(
        'info' => t('Tweet Button - None'), 
      );
    return $blocks;
    case 'view' :
      switch ($delta) {
        case 'tweetbutton_vertical' :
          $attributes['type'] = 'vertical';
          return array(
            'subject' => t(''), 
            'content' =>  theme('tweetbutton_display', NULL, $attributes)
          );
        case 'tweetbutton_horizontal' :
          $attributes['type'] = 'horizontal';
          return array(
            'subject' => t(''), 
            'content' =>  theme('tweetbutton_display', NULL, $attributes)
          );
        case 'tweetbutton_none' :
          $attributes['type'] = 'none';
          return array(
            'subject' => t(''), 
            'content' =>  theme('tweetbutton_display', NULL, $attributes)
          );
    }
    break;
  }
}
Jukebox’s picture

Thanks for the patch michaelfillier.

The only issue I had was that the blocks didn't seem to get cached correctly. Not entirely sure why. They would appear after I cleared the cache, but after a 2nd manual refresh, the block had lost its theming and inner html.

Following this post, I was able to correct this issue and make the block show correctly. I issued the following mysql command:

UPDATE blocks SET cache=-1 WHERE module='tweetbutton';

I'm sure there's a better solution out there, so this is just a temporary fix.