Adding and removing Actions from Silverstripe BulkManager

22 views Asked by At

Adding a bulk manager to a modelAdmin like this:

use Colymba\BulkManager;
class FAQAdmin extends ModelAdmin
{
public function getEditForm($id = null, $fields = null)
  {
      $form = parent::getEditForm($id, $fields);
      
      $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));

      $gridField->getConfig()->addComponent(new \Colymba\BulkManager\BulkManager());
      $gridField->getConfig()->getComponentByType('\Colymba\BulkManager\BulkManager')->removeBulkAction(\Colymba\BulkAction\UnlinkHandler::class);
    }
} 

I get error:

Bulk action 'Colymba\BulkAction\UnlinkHandler' or '' doesn't exists.

How can I add and remove the actions the bulk editor offers? I only want the publish action.

1

There are 1 answers

0
Will On

Looking at the relevent class the namespace is:

namespace Colymba\BulkManager\BulkAction;

and the classname is:

UnlinkHandler

So after quite a bit of trial and error, I got this working with:

$gridField->getConfig()->getComponentByType('\Colymba\BulkManager\BulkManager')->removeBulkAction(\Colymba\BulkManager\BulkAction\UnlinkHandler::class);

Which with hindsight is pretty obvious.