Issue #2928801 by xurizaemon, ericgsmith, geek-merlin, RoSk0, Gauravvvv, Rinku Jacob 13, hctom, benjifisher, Berdir: Remove hardcoded restriction of filesize formatter to fields named "filesize"

(cherry picked from commit e97d6c18f4)
merge-requests/6741/merge
Dave Long 2024-03-13 15:44:46 +00:00
parent b3acf741d9
commit 1bdd9d754b
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
1 changed files with 2 additions and 10 deletions

View File

@ -3,31 +3,23 @@
namespace Drupal\file\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\StringTranslation\ByteSizeMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Formatter that shows the file size in a human readable way.
* Formatter that shows the file byte size in a human-readable way.
*/
#[FieldFormatter(
id: 'file_size',
label: new TranslatableMarkup('File size'),
label: new TranslatableMarkup('Bytes (KB, MB, ...)'),
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}
*/