If someone once considers this, I got this working by overriding UserAdmin.php
add the following line to the registerBundle method of the application /AppKernel.php
// app/AppKernel.php public function registerBundles() { $bundles = array( // other bundle declarations new Sonata\UserBundle\SonataUserBundle(), ); }
Now set the value of the sonata.user.admin.user.class parameter to the FQCN of the User object that was created during the installation of the FOSUserBundle.
//app/config/config.yml parameters:
Now create a class that extends the UserAdmin class by default and overrides the configureShowFields, configureFormFields, configureDatagridFilters and configureListFields methods to add the necessary user admin fields. The following is an example of the extended UserAdmin class, which is based on a custom bone object created in the FOSUserBundle documentation.
<?php //src/YourVendor/YourBundle/Admin/UserAdmin.php namespace YourVendor\YourBundle\Admin; use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Show\ShowMapper; use FOS\UserBundle\Model\UserManagerInterface; use Sonata\AdminBundle\Route\RouteCollection; class UserAdmin extends BaseUserAdmin { /** * {@inheritdoc} */ protected function configureShowFields(ShowMapper $showMapper) { $showMapper ->with('General') ->add('username') ->add('email') ->end() // .. more info ; } /** * {@inheritdoc} */ protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('General') ->add('username') ->add('email') ->add('plainPassword', 'text', array('required' => false)) ->end() // .. more info ; if (!$this->getSubject()->hasRole('ROLE_SUPER_ADMIN')) { $formMapper ->with('Management') ->add('roles', 'sonata_security_roles', array( 'expanded' => true, 'multiple' => true, 'required' => false )) ->add('locked', null, array('required' => false)) ->add('expired', null, array('required' => false)) ->add('enabled', null, array('required' => false)) ->add('credentialsExpired', null, array('required' => false)) ->end() ; } } /** * {@inheritdoc} */ protected function configureDatagridFilters(DatagridMapper $filterMapper) { $filterMapper ->add('id') ->add('username') ->add('locked') ->add('email') ; } /** * {@inheritdoc} */ protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('username') ->add('email') ->add('enabled', null, array('editable' => true)) ->add('locked', null, array('editable' => true)) ->add('createdAt') ; if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) { $listMapper ->add('impersonating', 'string', array('template' => 'SonataUserBundle:Admin:Field/impersonating.html.twig')) ; } } }
Now set the value of sonata.user.admin.user.class to the FQCN of the created UserAdmin class in app / config / config.yml, for example
parameters: sonata.user.admin.user.class: YourVendor\YourBundle\Admin\UserAdmin
If everything is configured correctly, you will see a new line of users on the admin / dashboard page. All user actions should work as expected.