Customize Sonata-admin dashboard "home"

2.9k views Asked by At

I'm quite new to the Sonata project, and as "playing" with it, I wanted to use it for one of my projects.

But there are a few questions that still remains for me about Sonata and the way it works and can be customized.

Here are they :

  • Is it possible to use a custom controller to display the Dashboard "home"?
  • I'd like to use roles and only roles to manage my security but can't figure out how to add Roles to the list that is displayed when you use the users creation form (by default located at /admin/my/bundle/user/create) under the "management" tab. Is it possible? Screen to explain more : enter image description here

    If yes, if anyone has hints about how to do this, they are welcome! :)

  • Using this roles means managing the rights of these ones on my objects / controller. Is there any mechanism bundled for that or do I have to add mine?
2

There are 2 answers

7
Turdaliev Nursultan On BEST ANSWER

In symfony you can customize third party bundle by inheriting that bundle. So to use your own controller do the followings step by step:

In your custom bundle: AcmeDemoBundle.php add:

public function getParent()
{
    return 'SonataAdminBundle';
}

Now your bundle is inheriting SonataAdminBundle.

In your custom controller: AcmeDemoBundleCustomController.php

class CustomController extends CoreController {

  public function dashboardAction()
  {
      ...
      /* Here goes your code */
  }

}
1
Hugo Briand On

Turdaliev's answer is the correct way for your first question.

Regarding the roles, those displayed are those present in your application's security.yml file :

security:
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT, ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT]

In Sonata, an ACL mechanism is implemented, adding new roles for various actions such as view, delete, ... You may see a detailed example in the demo (https://github.com/sonata-project/sandbox), checkout the SonataAdmin security documentation for more details: http://sonata-project.org/bundles/admin/master/doc/reference/security.html