Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
Overrides FormatterInterface::viewElements
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
foreach ($items as $delta => $item) {
$output = $this
->numberFormat($item['value']);
// Account for prefix and suffix.
if ($this
->getSetting('prefix_suffix')) {
$prefixes = isset($instance['settings']['prefix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['prefix'])) : array(
'',
);
$suffixes = isset($instance['settings']['suffix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['suffix'])) : array(
'',
);
$prefix = count($prefixes) > 1 ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = count($suffixes) > 1 ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];
$output = $prefix . $output . $suffix;
}
$elements[$delta] = array(
'#markup' => $output,
);
}
return $elements;
}