function FileSize::viewElements

Same name in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php \Drupal\file\Plugin\Field\FieldFormatter\FileSize::viewElements()
  2. 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php \Drupal\file\Plugin\Field\FieldFormatter\FileSize::viewElements()
  3. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php \Drupal\file\Plugin\Field\FieldFormatter\FileSize::viewElements()

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\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
        $elements[$delta] = [
            '#markup' => format_size($item->value),
        ];
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.