16

IS there a simple way to disable some CRUD actions for given admin class? E.g. I just want a list of users added via front-end without the option to manually add them.

Bartosz Rychlicki
  • 1,918
  • 3
  • 20
  • 41
  • possible duplicate of [Syfmony2 sonata adminBundle without create action](http://stackoverflow.com/questions/17923343/syfmony2-sonata-adminbundle-without-create-action) – TautrimasPajarskas Aug 18 '13 at 10:01

1 Answers1

48

In your admin class :

protected function configureRoutes(RouteCollection $collection)
{
    // to remove a single route
    $collection->remove('delete');
    // OR remove all route except named ones
    $collection->clearExcept(array('list', 'show'));
}

Also use routeCollection at top of admin class

use Sonata\AdminBundle\Route\RouteCollection;

Docs : http://sonata-project.org/bundles/admin/master/doc/reference/routing.html#removing-a-single-route

wilsonrufus
  • 449
  • 1
  • 5
  • 14
rpg600
  • 2,800
  • 18
  • 24
  • 4
    How about if you needed to remove a route only when user is not assigned certain role? – Masinde Muliro Dec 24 '15 at 03:42
  • 1
    This works for one type of user, but if multiple users have different roles, the action gets saved in cache. On switching of roles, the cache is loaded and the roles are not checked. – marijnz0r May 11 '16 at 10:05