I'm trying to override the SonataUser/Admin/Model/UserAdmin
's configureFormFields()
because I need to remove some default fields from the admin form.
So I have copied the file vendor/bundles/Sonata/UserBundle/Admin/Model/UserAdmin.php
in my bundle app/Application/Sonata/UserBundle/Admin/Model/UserAdmin.php
and modified it. Then declared it as a service:
# app/application/Sonata/UserBundle/Resources/config/services.yml
services:
application_user.registration.form.type:
class: Application\Sonata\UserBundle\Admin\Model\UserAdmin
arguments: [%sonata_user.model.user.class%]
tags:
- { name: form.type, alias: application_user_admin }
Now questions: Am I doing right ? How can I tell sonata admin to use it ?
The overriding class should be set in config.yml:
# app/config/config.yml
sonata_user:
admin:
user:
class: MyCompany\UserBundle\Admin\Model\UserAdmin
Extend original UserAdmin:
namespace MyCompany\UserBundle\Admin\Model;
use Sonata\AdminBundle\Form\FormMapper;
class UserAdmin extends \Sonata\UserBundle\Admin\Model\UserAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
// new logic
}
}
Of course change class name MyCompany\UserBundle\Admin\Model\UserAdmin
to reflect your bundle structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With