tourze / easy-admin-attribute
EasyAdminBundle Attribute Extend
0.0.6
2025-03-30 13:00 UTC
Requires
- php: ^8.1
- chrisullyott/php-filesize: ^4.2
- easycorp/easyadmin-bundle: ^4
README
A PHP attribute extension for EasyAdmin Bundle that provides a comprehensive set of attributes to configure admin interfaces using PHP 8 attributes. This package simplifies EasyAdmin configuration by leveraging PHP 8's attribute system to create clean, type-safe admin interfaces.
Features
- Configure EasyAdmin entities using PHP 8 attributes
- Rich set of field types including Text, RichText, Select, ImagePicker and more
- CRUD operation attributes (List, Create, Edit, Delete, Copy, Import/Export)
- Advanced filtering and search capabilities
- Customizable form layouts and validations
- Automatic column formatting for common types (FileSize, Boolean, Images)
- Support for soft delete operations
- Flexible display conditions and sorting options
- Permission-based access control system
Requirements
- PHP 8.1 or higher
- EasyAdmin Bundle 4.x
- chrisullyott/php-filesize: ^4.2
Installation
You can install the package via composer:
composer require tourze/easy-admin-attribute
Quick Start
Basic Entity Configuration
<?php use Tourze\EasyAdmin\Attribute\Action\Listable; use Tourze\EasyAdmin\Attribute\Column\ListColumn; use Tourze\EasyAdmin\Attribute\Field\FormField; use Tourze\EasyAdmin\Attribute\Action\Deletable; #[Listable] #[Deletable(softDelete: true)] class Product { #[ListColumn(title: 'Product Name', sorter: true)] #[FormField(required: true)] private string $name; #[ListColumn(title: 'Price', columnType: 'money')] #[FormField(span: 12)] private float $price; #[ListColumn(title: 'Image')] #[FormField(allowRemote: true)] private string $image; }
Using Permissions
<?php use Tourze\EasyAdmin\Attribute\Permission\AsPermission; use Tourze\EasyAdmin\Attribute\Action\Listable; #[AsPermission(name: 'product', title: 'Product Management')] #[Listable(showTotal: true)] class Product { // Entity properties }
Available Attributes
Action Attributes
Listable
- Configure list view with pagination and sortingDeletable
- Enable delete operation with soft delete supportCopyable
- Add copy functionalityImportable
- Enable data import with template generation
Field Attributes
FormField
- Configure form fields with validation and layoutSelectField
- Create select fields with entity relationsRichTextField
- Rich text editor integrationImagePickerField
- Image upload and selectionImportField
- Configure import field mappings
Column Attributes
ListColumn
- Configure list view columnsExportColumn
- Specify export settingsImportColumn
- Define import field mappingsFileSizeColumn
- Automatic file size formattingPictureColumn
- Image display configurationBoolColumn
- Boolean value formattingCopyColumn
- Column copying configuration
Filter Attributes
Filterable
- Add filtering capabilitiesKeyword
- Enable keyword search on fields
Permission Attributes
AsPermission
- Configure permission-based access control
Configuration
Listable Configuration Options
#[Listable( showPagination: true, actionWidth: 120, scrollX: 'max-content', showTotal: true, totalTitleColumn: 'name', sortColumn: ['created_at' => 'DESC'] )]
FormField Configuration Options
#[FormField( required: true, span: 12, label: 'Custom Label', placeholder: 'Enter value here' )]
Advanced Usage
Custom Filtering
<?php use Tourze\EasyAdmin\Attribute\Filter\Filterable; use Tourze\EasyAdmin\Attribute\Filter\Keyword; #[Filterable] class Product { #[Keyword] private string $name; // Other properties }
Common Issues and Solutions
- If attributes aren't applied correctly, make sure your PHP version is 8.1 or higher
- For form validation issues, check that all required fields have the
required
parameter set - Permission issues may occur if the
AsPermission
attribute isn't configured properly
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.