You are here

public function StarRatingFormatter::formatterExecute in Star Rating 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/StarRatingFormatter.php \Drupal\starrating\Plugin\Field\FieldFormatter\StarRatingFormatter::formatterExecute()
  2. 8.2 src/Plugin/Field/FieldFormatter/StarRatingFormatter.php \Drupal\starrating\Plugin\Field\FieldFormatter\StarRatingFormatter::formatterExecute()
2 calls to StarRatingFormatter::formatterExecute()
StarRatingFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/StarRatingFormatter.php
Returns a short summary for the current formatter settings.
StarRatingFormatter::viewElements in src/Plugin/Field/FieldFormatter/StarRatingFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/StarRatingFormatter.php, line 135

Class

StarRatingFormatter
Plugin implementation of the 'Starrating' formatter.

Namespace

Drupal\starrating\Plugin\Field\FieldFormatter

Code

public function formatterExecute($rate, $min, $max, $icon_type, $icon_color, $fill_blank) {

  // Add hidden text to support copy/paste and voice reading
  // $out = '<span style="position:absolute;left:-9999px">' . $rate . '</span>
  // ';.
  $out = "<div class='starrating'>";
  for ($i = $min; $i < $max; $i++) {
    if ($i == $rate && !$fill_blank) {
      break;
    }
    if ($i >= $rate) {
      $class = $icon_type . '-off';
    }
    else {
      $class = $icon_type . $icon_color . '-on';
    }
    if ($i % 2) {
      $class .= ' odd';
    }
    else {
      $class .= ' even';
    }
    $class .= ' s' . ($i + 1);
    $out .= '<div class="rate-image ' . $class . '"></div>';
  }
  $out .= "</div>";
  return $out;
}