You are here

function fivestar_form in Fivestar 6.2

Same name and namespace in other branches
  1. 5 fivestar.module \fivestar_form()
  2. 6 fivestar.module \fivestar_form()

Create the fivestar form for the current item. Note that this is not an implementation of hook_form(). We should probably change the function to reflect that.

1 string reference to 'fivestar_form'
fivestar_forms in ./fivestar.module
Implementation of hook_forms().

File

./fivestar.module, line 657
A simple n-star voting widget, usable in other forms.

Code

function fivestar_form(&$form_state, $content_type, $content_id, $tag) {
  global $user;
  if ($content_type == 'node') {
    if (is_numeric($content_id)) {
      $node = node_load($content_id);
    }
    else {
      return array();
    }
  }
  $suffix = fivestar_get_suffix($node->type, $tag);
  $star_display = variable_get('fivestar_style_' . $suffix, 'average');
  $text_display = variable_get('fivestar_text_' . $suffix, '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($content_type, $content_id, $tag, 0);
  }
  else {
    $votes = fivestar_get_votes($content_type, $content_id, $tag);
  }
  $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 = fivestar_get_settings($node->type, $tag);
  $settings += array(
    'content_type' => $content_type,
    'content_id' => $content_id,
    'tag' => $tag,
    'autosubmit' => TRUE,
    'title' => FALSE,
  );
  return fivestar_custom_widget($form_state, $values, $settings);
}