You are here

function plus1_build_taxonomy_term_jquery_widget in Plus 1 7

Create voting widget to display on the webpage.

2 calls to plus1_build_taxonomy_term_jquery_widget()
plus1_taxonomy_term_view_alter in ./plus1.module
Implements hook_taxonomy_term_view_alter().
theme_plus1_json_response in theme/theme.inc
Theming function for json response.

File

./plus1.module, line 366

Code

function plus1_build_taxonomy_term_jquery_widget($entity_id, $tag = 'plus1_taxonomy_term_vote') {
  global $user;
  $term = taxonomy_term_load($entity_id);
  $score = plus1_get_score('taxonomy_term', $term->tid, $tag);
  $logged_in = $user->uid > 0;
  $voted = plus1_get_votes('taxonomy_term', $term->tid, $user->uid, $tag);
  $build = array(
    '#theme' => 'plus1_widget__taxonomy_term__' . $tag,
    '#weight' => (int) variable_get('plus1_taxonomy_widget_weight', '100'),
    '#entity_type' => 'taxonomy_term',
    '#entity_id' => $term->tid,
    '#tag' => $tag,
    '#score' => $score,
    '#logged_in' => $logged_in,
    '#is_author' => FALSE,
    '#voted' => $voted,
    '#vote_link' => 'plus1/vote/taxonomy_term/' . $term->tid . '/' . $tag,
    '#undo_vote_link' => 'plus1/undo-vote/taxonomy_term/' . $term->tid . '/' . $tag,
    '#link_query' => array(
      'token' => drupal_get_token($term->tid),
      plus1_get_cleared_destination(),
    ),
    '#can_vote' => user_access('plus1 vote on taxonomy_term'),
    '#can_undo_vote' => variable_get('plus1_taxonomy_term_undo_vote', 0),
    '#undo_vote_text' => check_plain(t(variable_get('plus1_taxonomy_term_undo_vote_text', ''))),
    '#voted_text' => check_plain(t(variable_get('plus1_taxonomy_term_voted_text', 'You voted'))),
    '#vote_text' => check_plain(t(variable_get('plus1_taxonomy_term_vote_text', 'Vote'))),
  );
  if (variable_get('plus1_add_js', 1)) {
    $build['#attached']['js'][] = drupal_get_path('module', 'plus1') . '/jquery.plus1.js';
  }
  if (variable_get('plus1_add_css', 1)) {
    $build['#attached']['css'][] = drupal_get_path('module', 'plus1') . '/plus1.css';
  }
  drupal_alter('plus1_widget', $build, $term);
  return $build;
}