How to remove fields from the admin user create page of Sonata User Bundle?

后端 未结 1 1333
时光说笑
时光说笑 2021-01-27 09:33

I have installed Sonata Admin Bundle and User Bundle in my Symfony 2.6 application. I found that the User bundle creates a bundle at src/Application/Sonata/UserBundle

相关标签:
1条回答
  • 2021-01-27 10:13

    Under configuration for sonata user bundle in config.yml i.e sonata_user you can override sonata user admin class and define your own admin class

    sonata_user
        admin:                  # Admin Classes
            user:
                class:          Application\Sonata\UserBundle\Admin\UserAdmin
                #Sonata\UserBundle\Admin\Entity\UserAdmin
                controller:     ApplicationSonataUserBundle:UserCURD /** you can also override CURD controller for your admin class*/
                translation:    SonataUserBundle
    

    Now create your user admin class in your extended bundle i.e ApplicationSonataUserBundle and extend your class with sonata's Sonata\UserBundle\Admin\Model\UserAdmin, now in configureFormFields() define your desired fields you want to add

    use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
    class UserAdmin extends BaseUserAdmin {
        protected function configureFormFields( FormMapper $formMapper ) {
         $formMapper->add('some field'); ...
         /** Do your stuff here */
        }
    }
    

    Or remove some of the fields :

    use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
    class UserAdmin extends BaseUserAdmin {
        protected function configureFormFields( FormMapper $formMapper ) {
            parent::configureFormFields($formMapper);
            $formMapper->remove('some field');
        }
    }
    

    See ADVANCED CONFIGURATION for sonata user bundle

    0 讨论(0)
提交回复
热议问题