Verified Commit e97d6c18 authored by Dave Long's avatar Dave Long
Browse files

Issue #2928801 by xurizaemon, ericgsmith, geek-merlin, RoSk0, Gauravvvv, Rinku...

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"
parent a15819d0
Loading
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -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}
   */