public function NumberExportFormatter::viewElements in REST Views 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldFormatter/NumberExportFormatter.php \Drupal\rest_views\Plugin\Field\FieldFormatter\NumberExportFormatter::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 NumericUnformattedFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ NumberExportFormatter.php, line 27
Class
- NumberExportFormatter
- Export a number as a serialized value.
Namespace
Drupal\rest_views\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) : array {
$elements = parent::viewElements($items, $langcode);
foreach ($elements as $delta => $element) {
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create(0 + $element['#markup']),
];
}
return $elements;
}