Manage FOSUser in EasyAdmin

EasyAdmin is a powerful backend generator, which creates magic with a simple Yaml file.

However, it has no support of FOSUserBundle, thanks to a specific opinion of the creator not to add too many “bridges” to the bundle for it to be the lightest possible.

But as EasyAdmin is great, we can easily implement users management directly in EasyAdmin.

As FOSUser uses some services to manage users, we have to add some logic inside our AdminController to make it work properly.

We assume here that you already have EasyAdmin installed on your app.

  1. First, Install FOSUserBundle and set it up to work the way you want (do not install FOSUserBundle 2, it’s not stable yet. Install FOSUserBundle 1.3).
    It might take you some time if you have not used it before, if so, feel free to  take the time you need to know how FOSUserBundle works.
  2. Then, add this config for EasyAdmin:
  3. If you do not have one already, create your own AdminController extending EasyAdmin’s one. Test it in your browser. You should see the User entity in your EasyAdmin menu.
  4. Add these three methods to your controller:

And you’re done for user management!
You can manually add other fields, but the most important is here.

Easy, isn’t it?

For groups, it’s very similar: activate groups management with FOSUserBundle, and add the groups field to your EasyAdmin’s User entity configuration under the form parameter.

Indeed you should manage groups as well so if you don’t have groups, you can’t set a group for a user, so you must create a backend for your Group entity. And as EasyAdmin is easy, you can do it yourself very easily!

Leave a Reply