0

I have extended the Sonata UserAdmin by creating Application\Sonata\UserBundle\Admin\Model\UserAdmin and extending Admin, then commenting out some fields I would rather not display.

From sonata_user in config.yml:

admin:                  # Admin Classes
    user:
        class:          Application\Sonata\UserBundle\Admin\Entity\UserAdmin
        controller:     SonataAdminBundle:CRUD
        translation:    SonataUserBundle

Where is the template for the form which gets displayed at /admin/sonata/user/user/{id}/editand what are the steps required to override it?

codecowboy
  • 9,835
  • 18
  • 79
  • 134

2 Answers2

0

The templates for your forms are in vendor/Sonata/...Resources/views

There are two ways to override these templates. The easiest is to override an individual template by creating it at app/Resources/PATH/view.html.twig. PATH => the path to access the view you override in vendor, you have to recreate it. I said view.html.twig, but it can be another name, just need to be the same.

So the same way you did with the UserAdmin entity, but in the resources.

The other way is in the case you did your own bundle, that will be the son of one of your vendors bundle.

To get more information, FOSUserBundle documentation is great about how to override things from a parent bundle. Check this : https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md There is also doc on how to override form & controllers.

Good luck !

codecowboy
  • 9,835
  • 18
  • 79
  • 134
ElPoney
  • 125
  • 1
  • 1
  • 9
  • Thanks for your edit, English isn't my nativ language, so thats quite hard for me. Hope I helped :) – ElPoney May 24 '14 at 13:00
0

Override getTemplate method in UserAdmin class:

public function getTemplate($name)
    {
        switch ($name) {
            case 'edit':
                return 'Application\Sonata:User:edit.html.twig';
                break;
            default:
                return parent::getTemplate($name);
                break;
        }
    }

and create Application\Sonata\Resources\views\User\edit.html.twig that will override Sonata's template:

{# edit.html.twig #}
{% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}

And now you can override the blocks from SonataAdminBundle:CRUD:edit.html.twig as you want.

Ioana Hazsda
  • 580
  • 3
  • 9