StarRatingValueFormatter.php in Star Rating 8
File
src/Plugin/Field/FieldFormatter/StarRatingValueFormatter.php
View source
<?php
namespace Drupal\starrating\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class StarRatingValueFormatter extends FormatterBase {
public static function defaultSettings() {
return parent::defaultSettings();
}
public function viewElements(FieldItemListInterface $items, $langcode) {
foreach ($items as $delta => $item) {
$rate = $item->value;
$output = '<div class="starrating">' . $item->value . '</div>';
$elements[$delta] = [
'#markup' => $output,
];
}
return $elements;
}
public function settingsSummary() {
$summary = [];
$field_settings = $this
->getFieldSettings();
$max = $field_settings['max_value'];
$output = '<div class="starrating">' . $max . '</div>';
$elements = [];
$elements['#markup'] = $output;
$summary[] = $elements;
return $summary;
}
}