Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
}
Comment | File | Size | Author |
---|---|---|---|
#2 | fivestar_0.patch | 1.04 KB | chellman |
Comments
Comment #1
chellman CreditAttribution: chellman commentedBetter version of the same thing, which also validates whether the content type supports voting.
Comment #2
chellman CreditAttribution: chellman commentedIt'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.
Comment #3
chellman CreditAttribution: chellman commentedYeah, I'm still learning how to use this issue queue. Changing post title.
Comment #4
vegeneric CreditAttribution: vegeneric commentedI like this feature a lot... kudos.
Comment #5
RobLoachVery nice feature... Reviewed the patch and it looks good to me!
Comment #6
Shivian Balaris CreditAttribution: Shivian Balaris commentedso... erm... I'm a noob... how do I patch the fivestar module? ((tries to hide))
Comment #7
RobLoachIf you just put what chellman posted in #1 into fivestar.module, you should be good.
Comment #8
quicksketchThanks! Persistence pays off :)
I had to fix some formatting problems (tabs instead of spaces), but committed and will be in the next version. Thanks!
Comment #9
(not verified) CreditAttribution: commented