Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / ranking.twig
1 /**
2  * Implements hook_ranking().
3  */
4 function {{ machine_name }}_ranking() {
5   // If voting is disabled, we can avoid returning the array, no hard feelings.
6   if (\Drupal::config('vote.settings')->get('node_enabled')) {
7     return [
8       'vote_average' => [
9         'title' => t('Average vote'),
10         // Note that we use i.sid, the search index's search item id, rather than
11         // n.nid.
12         'join' => [
13           'type' => 'LEFT',
14           'table' => 'vote_node_data',
15           'alias' => 'vote_node_data',
16           'on' => 'vote_node_data.nid = i.sid',
17         ],
18         // The highest possible score should be 1, and the lowest possible score,
19         // always 0, should be 0.
20         'score' => 'vote_node_data.average / CAST(%f AS DECIMAL)',
21         // Pass in the highest possible voting score as a decimal argument.
22         'arguments' => [\Drupal::config('vote.settings')->get('score_max')],
23       ],
24     ];
25   }
26 }