public function FileSize::viewElements in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php \Drupal\file\Plugin\Field\FieldFormatter\FileSize::viewElements()
- 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php \Drupal\file\Plugin\Field\FieldFormatter\FileSize::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
- core/
modules/ file/ src/ Plugin/ Field/ FieldFormatter/ FileSize.php, line 32
Class
- FileSize
- Formatter that shows the file size in a human readable way.
Namespace
Drupal\file\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => format_size($item->value),
];
}
return $elements;
}