You are here

public function YesNo::alterTemplateVariables in Vote Up/Down 8

Array containing all info for a plugin instance

Parameters

$variables:

Return value

mixed

Overrides VoteUpDownWidgetBase::alterTemplateVariables

File

src/Plugin/VoteUpDownWidget/YesNo.php, line 21

Class

YesNo
Provides the "yesno" Vote Up/Down widget

Namespace

Drupal\vud\Plugin\VoteUpDownWidget

Code

public function alterTemplateVariables(&$variables) {
  parent::alterTemplateVariables($variables);
  if ($variables['#unsigned_points'] == 0) {

    // No votes yet.
    $variables['#up_percent'] = 0;
  }
  else {
    $variables['#up_percent'] = $variables['#up_points'] / $variables['#unsigned_points'] * 100;
  }
  $variables['#percent_text'] = $this
    ->t('<em>@up_percent%</em> found this useful', [
    '@up_percent' => $variables['#up_percent'],
  ]);
}