I'm trying to modify the default admin of the User
entity.
Just need to remove certain fields from the form actually.
I imagine this doc will be usefull for me when it'll be available.
For now I have created this admin and tried to override the default User
one.
app/Application/Sonata/UserBundle/Admin/Model/UserAdmin.php
namespace Application\Sonata\UserBundle\Admin\Model;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\UserBundle\Admin\Model\UserAdmin as BaseType;
class UserAdmin extends BaseType
{
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('username')
->add('groups')
->add('enabled')
;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('username')
->add('email')
->add('plainPassword', 'text', array('required' => false))
->end()
->with('Groups')
->add('groups', 'sonata_type_model', array('required' => false))
->end()
->with('Profile')
->add('firstname', null, array('required' => false))
->add('lastname', null, array('required' => false))
->end()
;
}
/**
* {@inheritdoc}
*/
public function preUpdate($user)
{
$this->getUserManager()->updateCanonicalFields($user);
$this->getUserManager()->updatePassword($user);
}
/**
* @return UserManagerInterface
*/
public function getUserManager()
{
return $this->userManager;
}
}
app/config/config.yml
services:
sonata.admin.extension:
class: Application\Sonata\UserBundle\Admin\Model\UserAdmin
tags:
- { name: sonata.admin.extension, target: sonata.user.admin.user }
arguments: [null, Sonata\UserBundle\Entity\User, SonataUserBundle:UserAdmin]
But I'm getting
Cannot import resource "/var/www/Symfony/app/config/." from "/var/www/Symfony/app/config/routing.yml".
...
ErrorException: Catchable Fatal Error: Argument 1 passed to Sonata\AdminBundle\Admin\Admin::addExtension() must be an instance of Sonata\AdminBundle\Admin\AdminExtensionInterface, instance of Application\Sonata\UserBundle\Admin\Model\UserAdmin given, called in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 3139 and defined in /var/www/Symfony/vendor/bundles/Sonata/AdminBundle/Admin/Admin.php line 2359
What am I doing wrong ?