Integrate FOSUserBundle and SonataUserBundle Easily
SonataUserBundle is a great extension of SonataAdminBundle that provides user administration features by integrating FOSUserBundle user provider/management bundle. Its default installation procedure recommends to setup SonataUserBundle as child bundle of FOSUserBundle and generate ApplicationSonataUserBundle via sonata:easy-extends:generate command. But on some cases you may not want to setup that way. For example you have setup your user entity by following the documentation of FOSUserBundle before integrating SonataAdminBundle and SonataUserBundle, you may want to override both bundles separately. In following section I will outline how to integrate SonataUserBundle with FOSUserBundle without creating child bundle of FOSUserBundle.
Now setup SonataUserBundle. Add it to composer.json and add following line into registerBundle method of app/AppKernel.php
app/AppKernel.php
123456789
// app/AppKernel.phppublicfunctionregisterBundles(){$bundles=array(// other bundle declarationsnewSonata\UserBundle\SonataUserBundle(),);}
Then setup configuration, add routing and security configuration according to the documentation.
Now set value of sonata.user.admin.user.class parameter to the FQCN of the User entity which was created during FOSUserBundle setup. For example if FQCN of your user entity is YourVendor\YourBundle\Entity\User then parameter setting of app/config.yml would be
Now create a class that extends default UserAdmin class and override configureShowFields, configureFormFields, configureDatagridFilters and configureListFields methods to add the needed user admin fields. Following is the sample extended UserAdmin class which is based on the bare bone user entity created in FOSUserBundle documentation.