function template_preprocess_rate_template_yesno in Rate 8
Implements hook_preprocess_HOOK() for rate-template-yes_no.html.twig.
File
- ./
rate.module, line 332 - Hook implementation code for the Rate module.
Code
function template_preprocess_rate_template_yesno(&$variables) {
$vote_types = [
'yes' => '1',
'no' => '-1',
];
foreach ($vote_types as $vote_type => $value) {
$variables[$vote_type . '_li_attributes'] = new Attribute();
$variables[$vote_type . '_li_attributes']['class'] = [];
$variables[$vote_type . '_li_attributes']['class'][] = 'rate-' . $vote_type;
$variables[$vote_type . '_attributes'] = new Attribute();
$variables[$vote_type . '_attributes']['class'] = [];
$variables[$vote_type . '_attributes']['class'][] = 'rate-yesno-btn';
$variables[$vote_type . '_attributes']['class'][] = 'rate-' . $vote_type . '-btn';
// Add a class if the current user has voted on this item.
if ($variables['user_voted'] === $value) {
$variables[$vote_type . '_li_attributes']['class'][] = 'rate-voted';
}
if ($variables['use_ajax'] && !$variables['has_voted'] && $variables['can_vote']) {
$variables[$vote_type . '_attributes']['class'][] = 'use-ajax';
}
}
$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;
$variables['score_attributes'] = new Attribute();
$variables['score_attributes']['class'] = [];
$variables['score_attributes']['class'][] = 'rate-yesno-votes';
_rate_set_common_theme_variables($variables, TRUE);
_rate_get_undo_link($variables);
$variables['#attached']['library'][] = 'rate/yesno';
}