FileSize.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php
- 9 core/modules/views/src/Plugin/views/field/FileSize.php
- 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php
- 10 core/modules/views/src/Plugin/views/field/FileSize.php
- 11.x core/modules/file/src/Plugin/Field/FieldFormatter/FileSize.php
- 11.x core/modules/views/src/Plugin/views/field/FileSize.php
Namespace
Drupal\file\Plugin\Field\FieldFormatterFile
-
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;
/**
* Formatter that shows the file size in a human readable way.
*
* @FieldFormatter(
* id = "file_size",
* label = @Translation("File size"),
* field_types = {
* "integer"
* }
* )
*/
class FileSize extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return parent::isApplicable($field_definition) && $field_definition->getName() === 'filesize';
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => format_size($item->value),
];
}
return $elements;
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
FileSize | Formatter that shows the file size in a human readable way. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.