public function PriceDefaultFormatter::viewElements in Price 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldFormatter/PriceDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceDefaultFormatter::viewElements()
- 3.x src/Plugin/Field/FieldFormatter/PriceDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceDefaultFormatter::viewElements()
- 2.x src/Plugin/Field/FieldFormatter/PriceDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceDefaultFormatter::viewElements()
- 3.0.x src/Plugin/Field/FieldFormatter/PriceDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceDefaultFormatter::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
1 method overrides PriceDefaultFormatter::viewElements()
- PriceCalculatedFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ PriceCalculatedFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ PriceDefaultFormatter.php, line 138
Class
- PriceDefaultFormatter
- Plugin implementation of the 'price_default' formatter.
Namespace
Drupal\price\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$options = $this
->getFormattingOptions();
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => $this->currencyFormatter
->format($item->number, $item->currency_code, $options),
'#cache' => [
'contexts' => [
'languages:' . LanguageInterface::TYPE_INTERFACE,
'price_country',
],
],
];
}
return $elements;
}