I wanted fivestar in a block instead of in the content of a node, so I added this function to my copy. It seems to work, but I'm not a very advanced Drupal developer right now, so a sanity check would be a good idea. I stole the form of this from community_tags, which can be inline or in a block, so it seemed like a good place to start.

function fivestar_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Fivestar: Rate This');
      return $block;

    case 'view':
      if (user_access('access content') && user_access('rate content')) {
        if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == '' || arg(2) == 'view')) {
          $node = node_load(arg(1));
          
          $block['subject'] = t('Rate This');
          $block['content'] = fivestar_widget_form($node);
          return $block;
        }
      }
      
      break;
  }
}
CommentFileSizeAuthor
#2 fivestar_0.patch1.04 KBchellman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chellman’s picture

Better version of the same thing, which also validates whether the content type supports voting.

function fivestar_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Fivestar: Rate This');
      return $blocks;

    case 'view':
      if (user_access('access content') && user_access('rate content')) {
        if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == '' || arg(2) == 'view')) {
          $node = node_load(arg(1));
          
          if (_fivestar_validate_target('node', $node->nid)) {
			  $block['subject'] = t('Rate This');
			  $block['content'] = fivestar_widget_form($node);
          }
          
          return $block;
        }
      }
      
      break;
  }
}
chellman’s picture

Title: Fivestar in a block (with patch!) » This time the patch is *really* a patch
Version: 5.x-1.5 » 5.x-1.7
FileSize
1.04 KB

It's not a huge deal to add this into each of the releases, but maybe making a proper patch out of this will get some more attention. Even the kind of attention where someone says "come on, this is a lame patch, you can do better". I think having fivestar rating capability in a block is useful, so I'm keeping at it.

This patch is against version 1.7.

chellman’s picture

Title: This time the patch is *really* a patch » Allow fivestar rating in a block
Status: Active » Needs review

Yeah, I'm still learning how to use this issue queue. Changing post title.

vegeneric’s picture

I like this feature a lot... kudos.

RobLoach’s picture

Status: Needs review » Reviewed & tested by the community

Very nice feature... Reviewed the patch and it looks good to me!

Shivian Balaris’s picture

so... erm... I'm a noob... how do I patch the fivestar module? ((tries to hide))

RobLoach’s picture

If you just put what chellman posted in #1 into fivestar.module, you should be good.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Persistence pays off :)

I had to fix some formatting problems (tabs instead of spaces), but committed and will be in the next version. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)