定制 tourze/easy-admin-file-size-field-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/easy-admin-file-size-field-bundle

最新稳定版本:1.0.0

Composer 安装命令:

composer require 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

README 文档

README

PHP Version Symfony Version License Build Status Code Coverage

English | 中文

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_bytes filter 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.

统计信息

  • 总下载量: 235
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-07