views:

418

answers:

1

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 everything a permanent 10 stars. :(

A: 

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.

Nikit
Thanks for your help. I wasn't able to get this to work, I edited my question with my attempt.
Jourkey
ah, forgot about:create function of your code, and call in this manner:print drupal_get_form('yourformfunction', $object, etc variables);I think, also theming fivestar form will useful...
Nikit
I'm sorry... I have no idea what you mean. Could you please please be more specific. I'm totally lost, especially where you put variables. What params do I need in both the function and the drupal get form. Also is it alright to replace the content_type and id, I think they might've not been what I thought they meant. Thanks. Is content_type the type of content, or it user/node/etc. I'm so lost, please help. Thanks!
Jourkey
What is etc variables?
Jourkey
etc = some variables, if you don't want pass them (for more dynamic behaviour), you can miss these...
Nikit
Well then what do you put into the params for my function? Just yourformfunction($object) ?
Jourkey