开发者

Drupal: Fivestar Block with voting axis

开发者 https://www.devze.com 2022-12-17 02:37 出处:网络
I\'m using fivestar 1.19 with voting axis. I believe the default fivestar block/fivestar function uses only the default \'vote\' tag.

I'm using fivestar 1.19 with voting axis. I believe the default fivestar block/fivestar function uses only the default 'vote' tag.

fivestar_widget_form($node)

I need to pass my custom fivestar tag to the function.

Attempting to follow the answer below: For me $object is $node.

  <?php 
function custom_fivestar_widget ($object) {
  global $user;

  $star_display = variable_get('fivestar_style_'. $object->type, 'average');
  $text_display = variable_get('fivestar_text_'. $object->type, 'dual');

  if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
    // Save a query and don't retrieve the user vote unnecessarily.
    $votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
  }
  else {
    $votes = fivestar_get_votes($object->type, $object->nid);
  }

  $values = array(
    'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
    'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
    'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
  );

  $settings = array(
    'stars' => variable_get('fivestar_stars_'. $object->type, 10),
    'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
    'style' => $star_display,
    'text' => $text_display,
    'content_type' => $object->type,
    'content_id' => $object->nid,
    'tag' => 'score',
    'autosubmit' => TRUE,
    'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
    'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
    'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
    'labels' => variable_get('fivestar_labels_'. $object->type, array()),
  );

  return fivestar_custom_widget($form_state, $values, $settings);
}

print drupal_get_form('custom_fivestar_widget', $object);

?>

This prints me the widget, I believe using my score. However the text display is all wrong, as is the average score. And it gives ever开发者_如何学运维ything a permanent 10 stars. :(


You can reproduce fivestar_form function in fivestar.module. See there $settings variable.
So just copy inner of this function, remove some variables checking and set manually some variables. In $settings array set to 'tag' value as you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消