5
votes

Symfony 2.3.25, SonataAdminBundle

If i remove the 'delete' route from my admin by

$collection->clearExcept(array('list'));

in configureRoutes I get no 'batch' column in List View, which is what I want.

But I need the 'delete' action.

When I configureRoutes:

$collection->clearExcept(array('list', 'delete'));

I get the 'batch' column back, which I do not want. I do not want any batch actions or batch columns or anything batch.

I do want a 'Delete' button per row in an Actions column, which I get.

How do I suppress the batch column in list view?

3

3 Answers

19
votes

You can remove or add batch actions by overriding the batchActions method. You just have to add your own batchActions method in your Admin class.

To remove the delete action you have to do this :

class Admin
{
    public function getBatchActions()
    {
        $actions = parent::getBatchActions();
        unset($actions['delete']);

        return $actions;
    }
}

The documentation of the default SonataAdmin batchActions method : https://github.com/sonata-project/SonataAdminBundle/blob/master/Admin/Admin.php#L1142

2
votes

Update for year 2016+. Now you can customize batch actions by using:

configureBatchActions method inside your Admin class.

 /**
  * Allows you to customize batch actions.
  *
  * @param array $actions List of actions
  *
  * @return array
  */
 protected function configureBatchActions($actions)
 {
     return $actions;
 }
1
votes

You also can use the following:

/**
 * {@inheritdoc}
 */
public function configureBatchActions($actions)
{
    if (isset($actions['delete'])) {
        unset($actions['delete']);
    }

    return $actions;
}