annotate vendor/chi-teck/drupal-code-generator/templates/d8/hook/ranking.twig @ 5:12f9dff5fda9
tip
Update to Drupal core 8.7.1
author |
Chris Cannam |
date |
Thu, 09 May 2019 15:34:47 +0100 |
parents |
c75dbcec494b |
children |
|
rev |
line source |
Chris@0
|
1 /**
|
Chris@0
|
2 * Implements hook_ranking().
|
Chris@0
|
3 */
|
Chris@0
|
4 function {{ machine_name }}_ranking() {
|
Chris@0
|
5 // If voting is disabled, we can avoid returning the array, no hard feelings.
|
Chris@0
|
6 if (\Drupal::config('vote.settings')->get('node_enabled')) {
|
Chris@0
|
7 return [
|
Chris@0
|
8 'vote_average' => [
|
Chris@0
|
9 'title' => t('Average vote'),
|
Chris@0
|
10 // Note that we use i.sid, the search index's search item id, rather than
|
Chris@0
|
11 // n.nid.
|
Chris@0
|
12 'join' => [
|
Chris@0
|
13 'type' => 'LEFT',
|
Chris@0
|
14 'table' => 'vote_node_data',
|
Chris@0
|
15 'alias' => 'vote_node_data',
|
Chris@0
|
16 'on' => 'vote_node_data.nid = i.sid',
|
Chris@0
|
17 ],
|
Chris@0
|
18 // The highest possible score should be 1, and the lowest possible score,
|
Chris@0
|
19 // always 0, should be 0.
|
Chris@0
|
20 'score' => 'vote_node_data.average / CAST(%f AS DECIMAL)',
|
Chris@0
|
21 // Pass in the highest possible voting score as a decimal argument.
|
Chris@0
|
22 'arguments' => [\Drupal::config('vote.settings')->get('score_max')],
|
Chris@0
|
23 ],
|
Chris@0
|
24 ];
|
Chris@0
|
25 }
|
Chris@0
|
26 }
|