You are here

public function StarRatingValueFormatter::viewElements in Star Rating 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Field/FieldFormatter/StarRatingValueFormatter.php \Drupal\starrating\Plugin\Field\FieldFormatter\StarRatingValueFormatter::viewElements()
  2. 8.2 src/Plugin/Field/FieldFormatter/StarRatingValueFormatter.php \Drupal\starrating\Plugin\Field\FieldFormatter\StarRatingValueFormatter::viewElements()
  3. 8.3 src/Plugin/Field/FieldFormatter/StarRatingValueFormatter.php \Drupal\starrating\Plugin\Field\FieldFormatter\StarRatingValueFormatter::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/StarRatingValueFormatter.php, line 32

Class

StarRatingValueFormatter
Plugin implementation of the 'addtocart' formatter.

Namespace

Drupal\starrating\Plugin\Field\FieldFormatter

Code

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;
}