Sonata Admin Control Panel: Configuring Actions for Each Object

I am using SonataAdminBundle as the base for the administration interface for a website with support for Symfony2 (v2.0.x).

Objects added to the control panel in SonataAdmin have the following actions by default:

  • add
  • list

This is great for most objects, but there are several objects on the website for which data is not added through the admin interface, i.e. they are entered from a public website. Administrators only need to view them (the "list" action on the control panel), edit them or delete them. Administrators should not be able to add data to these objects.

Is there a way to configure what actions are displayed next to individual objects in the SonataAdmin control panel?

+5
php symfony sonata-admin symfony-sonata
source share
2 answers

In your EntityAdmin class add the following

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

To remove one route from the Admin class, use

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

In Symfony 2.1 +, you can use clearExcept to delete all routes except those specified, for example this:

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

This has the advantage that you save your actions as they are when you add new actions to the SonataAdminBundle .

Symfony 2.0 has a similar undocumented feature (thanks to Jeroen):

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

All Articles