Sonata Admin Dashboard: configure actions per entity

非 Y 不嫁゛ 提交于 2019-12-05 00:34:28

问题


I'm using the SonataAdminBundle as base for an administration interface for a Symfony2 (v2.0.x) powered website.

Entities which are added to the dashboard in SonataAdmin have the following actions by default:

  • add
  • list

This works fine for most entities, however the website has a few entities for which data is not added via the admin interface - i.e. they are entered from the public facing website. Administrators only need to view them ("list" action in dashboard), edit them or delete them. Administrators should not be able to add data to these entities.

Is there a way to configure which actions are displayed next to individual entities in SonataAdmin dashboard?


回答1:


In your EntityAdmin class add following

public function configureRoutes(RouteCollection $collection)
{
  $collection->remove('create');
}



回答2:


To remove a single route from your Admin class, use

protected function configureRoutes(RouteCollection $collection)
    {
        $collection->remove('edit');
    }

In Symfony 2.1+, you might use clearExcept to remove all routes except the ones given, like this:

public function configureRoutes(RouteCollection $collection)
{
  $collection->clearExcept(array('list', 'edit', 'delete', 'batch'))
}

This has the advantage of keeping your actions as they are in case of new actions being added to SonataAdminBundle.

In Symfony 2.0, there is a similar undocumented function as well (thanks Jeroen):

public function configureRoutes(RouteCollection $collection)
{
  $collection->removeAllExcept(array('list', 'edit', 'delete', 'batch'))
}


来源:https://stackoverflow.com/questions/9587431/sonata-admin-dashboard-configure-actions-per-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!