What is EasyAdmin?
EasyAdmin is a wonderful framework for Symfony that allows developers to build very powerful admin interfaces. Very easily a developer can spin up interfaces for users that allow them to interact with a specified set of entities, for example to run a blog or manage some products. We use Easy Admin in nearly all our projects, as its very neatly integrated with Symfony, but also actively developed. We even contributed to the package a couple of times already. EasyAdmin allows developers to build really strong and versatile backends, and together with Symfony its a really strong software project.
The Problem with EasyAdmin
Default Limitations
Although EasyAdmin is known for its straight forward user interface and the ability to customize according to individual needs, it has some drawdowns. For example the design of the codebase. Whilst some classes are marked as final, they do not implement any kind of Interfaces. Usually when approaching this design pattern, you always want to implement Interfaces or at least focus on the SOLID principle, so that other developers can write tests for their business logic. In general, that would be the preferred approach. But since Symfony has so many contributers, there are also so many ideas how code should look like. This is typical. The more developers you have, the more good and bad ideas you will get. Another problem with EasyAdmin is that it can be hard and frustrating to bring code improvments in, as there is no real order of command and basically the owners is signing off every single contribution by himself; naturally, nobody has so much time to maintain such a package next to their daily job. Meaning that many Pull Requests are open for a long time, demotivating the contributers. Frankly, this is understandable.But the real challenge is not withing this kind of merging strategy, but in the narrow and somewhat suboptimal developed spaces inside the code that are not extensible.
Complexity of Customization
Now lets say you want to add a new field - straight forward! Its very easy to create a new field in your own codebase and using it. But if you want to contribute that logic into EasyAdmin directly, it can be more challenging. A good example for this is the lack of a Field that allows developers to implement classic File Upload Fields. One could say that these fields might bring in Security issues and whilst we'd agree with this statement, isn't that up to the developer to secure? Depending on how you see Open Source projects you might agree. In our case we wanted to have a File Field. There is an Image Field that has everything we need, but we want to adapt a small fraction of the code, just so much that we can upload Files, together with Images in one field.
The Solution: EasyAdmin File Upload Field Plugin
A little big more Freedom for Developers
We work with a client that needs to upload given files. Word documents, PDFs, CSVs, you name it - its not possible with the current branch of EasyAdmin. For this reason we developed our own little package, kept it tightly to the code standards of EasyAdmin and published it to composer for you to use it very easily.
Usage
If you find yourself in a situation where you want to have File Fields as well, you can go ahead and use our free EasyAdmin Field bundle for free. Simply type:
composer require bytescommerce/easy-admin-file-upload-field
You should by now use PHP 8 and Symfony 7, so you should have Flex enabled. In this case, the bundle will register itself with the developers EasyAdmin application. Now, its very easy to integrate it.
The old ImageField can now be replaced with our FileField:
yield FileField::new('filename', t('File'))->setBasePath(sprintf('%s', File::BASE_FILE_PATH))->setUploadDir(sprintf('public/%s', File::BASE_FILE_PATH))->setUploadedFileNamePattern('[name].[extension]')->setColumns('col-sm-12 col-md-6');
As you can see, not much changes here. We only replaced "ImageField" with FileField and imported our class to be used succesfully. And thats it, the bundle will re-use the ImageField assets and resources, but manipulates the upload constraints.
Advantages of Our Plugin
Easy Installation
Thanks to composer you can absolutely don't waste your time on installation. Like its common in the Symfony world, packages are provided with composer quite easily.
Versatile Applications
Our plugin stands out due to its versatility. Whether it is about uploading images, documents, or other file formats, the integration of this component into the EasyAdmin backend brings significant advantages. The plugin offers the necessary flexibility to efficiently manage various file types, making it the ideal solution for a wide range of use cases.
Same User Interface as before!
Your users won't even notice. Since we do re-use all components from the classic ImageField, there is not even a slight change in the UI. It remains absolutely the same.
Contributions
If you find yourself in a situation where you have found a bug in our code, feel free to open a PR with us; we are happy to receive your input.
Find the project on Github!