FileSize.php in Zircon Profile 8.0
File
core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php
View source
<?php
namespace Drupal\file\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
class FileSize extends FormatterBase {
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return parent::isApplicable($field_definition) && $field_definition
->getName() === 'filesize';
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => format_size($item->value),
];
}
return $elements;
}
}
Classes
Name |
Description |
FileSize |
Formatter that shows the file size in a human readable way. |