You are here

function template_preprocess_rate_template_number_up_down in Rate 8

Implements hook_preprocess_HOOK() for rate-template-number-up-down.html.twig.

File

./rate.module, line 176
Hook implementation code for the Rate module.

Code

function template_preprocess_rate_template_number_up_down(&$variables) {
  $vote_types = [
    'up',
    'down',
  ];
  foreach ($vote_types as $vote_type) {
    $variables[$vote_type . '_attributes'] = new Attribute();
    $variables[$vote_type . '_attributes']['class'] = [];
    $variables[$vote_type . '_attributes']['class'][] = 'rate-number-up-down-btn-' . $vote_type;
    if ($variables['use_ajax'] && !$variables['has_voted'] && $variables['can_vote']) {
      $variables[$vote_type . '_attributes']['class'][] = 'use-ajax';
    }
  }
  $score = isset($variables['results']['updown']['vote_sum']) ? $variables['results']['updown']['vote_sum'] : 0;
  if ($score > 0) {
    $score = '+' . $score;
    $score_class = 'positive';
  }
  elseif ($score < 0) {
    $score_class = 'negative';
  }
  else {
    $score_class = 'neutral';
  }
  $variables['score'] = $score;
  $variables['score_attributes'] = new Attribute();
  $variables['score_attributes']['class'] = [];
  $variables['score_attributes']['class'][] = 'rate-number-up-down-rating';
  $variables['score_attributes']['class'][] = $score_class;
  $variables['up_votes'] = isset($variables['results']['updown']['rate_count_up']) ? $variables['results']['updown']['rate_count_up'] : 0;
  $variables['down_votes'] = isset($variables['results']['updown']['vote_count']) ? $variables['results']['updown']['vote_count'] - $variables['up_votes'] : 0;
  _rate_set_common_theme_variables($variables);
  _rate_get_undo_link($variables);
  $variables['#attached']['library'][] = 'rate/number-up-down';
}