You are here

function template_preprocess_fivestar_formatter_percentage in Fivestar 8

Implements hook_preprocess_HOOK() for the Fivestar percentage formatter.

File

./fivestar.module, line 272
A simple n-star voting widget, usable in other forms.

Code

function template_preprocess_fivestar_formatter_percentage(array &$variables) {
  $element = $variables['element'];

  // Get average, which ranges from 0 to 100.
  $average = $element['#item']['average'];
  if (empty($average)) {
    $average = 0;
  }

  // Set average variable.
  $variables['average'] = round($average, 1);
}