tourze / easy-admin-file-size-field-bundle
A Symfony bundle that provides a file size field for EasyAdmin, automatically formatting byte values into human-readable formats
Installs: 212
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/easy-admin-file-size-field-bundle
Requires
- php: ^8.1
- chrisullyott/php-filesize: ^4.2
- easycorp/easyadmin-bundle: ^4
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/expression-language: ^6.4
- symfony/form: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/messenger: ^6.4
- symfony/options-resolver: ^6.4
- symfony/property-access: ^6.4
- symfony/string: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- twig/twig: ^3.13|^4.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^6.4
This package is auto-updated.
Last update: 2025-10-31 07:32:51 UTC
README
A Symfony bundle that provides a file size field for EasyAdmin, automatically formatting byte values into human-readable formats (KB, MB, GB, etc.).
Features
- Automatic formatting: Converts raw byte values into human-readable formats (B, KB, MB, GB, TB)
- Twig integration: Provides a format_bytesfilter for use in templates
- Easy integration: Works seamlessly with EasyAdmin's field system
- Customizable: Supports all standard EasyAdmin field options
Installation
Install the bundle using Composer:
composer require tourze/easy-admin-file-size-field-bundle
Quick Start
In your EasyAdmin CRUD controller, use the FileSizeField to display file sizes:
<?php namespace App\Controller\Admin; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use Tourze\EasyAdminFileSizeFieldBundle\Field\FileSizeField; use App\Entity\File; class FileCrudController extends AbstractCrudController { public static function getEntityFqcn(): string { return File::class; } public function configureFields(string $pageName): iterable { return [ IdField::new('id'), TextField::new('name'), FileSizeField::new('size', 'File Size'), ]; } }
Usage
In EasyAdmin Controllers
// Basic usage FileSizeField::new('fileSize') // With custom label FileSizeField::new('fileSize', 'Document Size') // With additional options FileSizeField::new('fileSize', 'Size') ->setHelp('The size of the uploaded file') ->hideOnIndex()
In Twig Templates
You can also use the format_bytes filter directly in your Twig templates:
{{ file.size|format_bytes }}
{# Output: "1.5 MB" #}
{{ 1024|format_bytes }}
{# Output: "1 KB" #}
Advanced Usage
Custom Formatting Options
The FileSizeField supports additional configuration options:
FileSizeField::new('fileSize') ->setTemplatePath('admin/custom_file_size.html.twig') ->addCssClass('file-size-custom') ->setFormTypeOptions([ 'precision' => 2, 'binary' => true, // Use 1024 instead of 1000 as base ])
Form Type Integration
You can also use the form type directly in your forms:
use Tourze\EasyAdminFileSizeFieldBundle\Form\FileSizeType; public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('maxFileSize', FileSizeType::class, [ 'label' => 'Maximum File Size', ]) ; }
Configuration
The bundle registers itself automatically when installed. No additional configuration is required.
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- EasyAdmin 4.0 or higher
License
This bundle is released under the MIT license. See the LICENSE file for details.