You are here

public function VotingApiWidgetBase::getVoteSummary in Votingapi Widgets 8

Generate summary.

File

src/Plugin/VotingApiWidgetBase.php, line 283

Class

VotingApiWidgetBase
Base class for Voting api widget plugins.

Namespace

Drupal\votingapi_widgets\Plugin

Code

public function getVoteSummary(ContentEntityInterface $vote) {
  $results = $this
    ->getResults($vote);
  $field_name = $vote->field_name->value;
  $fieldResults = [];
  foreach ($results as $key => $result) {
    if (strrpos($key, $field_name) !== FALSE) {
      $key = explode(':', $key);
      $fieldResults[$key[0]] = $result != 0 ? ceil($result * 10) / 10 : 0;
    }
  }
  return [
    '#theme' => 'votingapi_widgets_summary',
    '#vote' => $vote,
    '#results' => $fieldResults,
    '#field_name' => $vote->field_name->value,
  ];
}