Easyadminbundle: [Feature Request] Custom controllers per entity

Created on 10 Feb 2016  路  5Comments  路  Source: EasyCorp/EasyAdminBundle

First, what a great bundle. So much better and easier to use that other "Shall not be named" bundle.

One thing I have noticed is that all customizations need to be added to a derived AdminController. This is fine for a few tweaks, but for a large scale application it will become difficult to manage. For example, I have about 30 entities, most of them have fields which do not require being shown in the admin list. That means my derived controller already has 30 methods. See where I'm going?

I propose allowing the separation of code and allowing users to create an Admin class, also derived from AdminController, solely for a bundle or entity. This would also allow 3rd party bundles to 'plug in'. So for example if I have an entity at 'MyBundle\Entity\User', I would like to have a class containing admin controller methods at 'MyBundleAdmin\UserAdmin'.

This would probably involve adding a new config value like:

easy_admin:
    controllers:
        MyBundle\Entity\User: MyBundle\Admin\UserAdmin

Then in the indexAction, before initialization, check if the entity has an associated controller and pass execution to it. This would also require the new controller implement an interface of course.

BTW, sorry about the title, clicked before checking now I can't figure out hot to edit it.

feature hasPR

Most helpful comment

@twifty thanks for your kind comments. This is definitely a problem for medium-sized backends and I want to solve it. I've been thinking about this, but I still don't know which is the best way to solve it.

A temporary solution could be to use traits in your admin controller:

use AppBundle\Controller\Admin\UserAdmin;
use AppBundle\Controller\Admin\ProductAdmin;

class AdminController extends BaseController
{
    use UserAdmin;
    use ProductAdmin;
    // ...
}

// ...

namespace AppBundle\Controller\Admin;

trait UserAdmin
{
    // ...
}

All 5 comments

@twifty thanks for your kind comments. This is definitely a problem for medium-sized backends and I want to solve it. I've been thinking about this, but I still don't know which is the best way to solve it.

A temporary solution could be to use traits in your admin controller:

use AppBundle\Controller\Admin\UserAdmin;
use AppBundle\Controller\Admin\ProductAdmin;

class AdminController extends BaseController
{
    use UserAdmin;
    use ProductAdmin;
    // ...
}

// ...

namespace AppBundle\Controller\Admin;

trait UserAdmin
{
    // ...
}

@javiereguiluz I will fork the project and, when I get time, apply my ideas.

Added a pull request

+1 for this feature

Closing it as fixed by #1185.

Was this page helpful?
0 / 5 - 0 ratings