Add notes on adding and removing actions as it wasn't obvious for me on first look.
2.2 KiB
Bulk Manager
Perform actions on multiple records straight from the GridField. Comes with unlink, delete and bulk editing. You can also easily create/add your own.
Usage
Simply add component to your GridFieldConfig
$config->addComponent(new \Colymba\BulkManager\BulkManager());
Configuration
The component's options can be configurated individually or in bulk through the 'config' functions like this:
$config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($reference, $value);
$config overview
The available configuration options are:
- 'editableFields' : array of string referencing specific CMS fields available for editing
Removing and Adding actions
To remove an action call removeBulkAction using the fully namespaced classname.
$gridField->getConfig()->getComponentByType('\Colymba\BulkManager\BulkManager')->removeBulkAction(\Colymba\BulkManager\BulkAction\UnlinkHandler::class);
To add an action:
$gridField->getConfig()->getComponentByType('\Colymba\BulkManager\BulkManager')->addBulkAction(\Colymba\BulkManager\BulkAction\UnlinkHandler::class);
Custom actions
You can remove or add individual action or replace them all via addBulkAction()
and removeBulkAction()
Adding a custom action
To add a custom bulk action to the list use:
$config
->getComponentByType('Colymba\\BulkManager\\BulkManager')
->addBulkAction('Namespace\\ClassName')
Custom action handler
When creating your own bulk action RequestHandler
, you should extend Colymba\BulkManager\BulkAction\Handler
which will expose 2 useful functions getRecordIDList()
and getRecords()
returning either an array with the selected records IDs or a DataList
of the selected records.
Make sure to define the handler's $url_segment
, from which the handler will be called and its relating $allowed_actions
and $url_handlers
. See Handler
, DeleteHandler
and UnlinkHandler
for examples.
Front-end config
Bulk action handler's front-end configuration is set via class properties label
, icon
, buttonClasses
, xhr
and destructive
. See Handler
, DeleteHandler
and UnlinkHandler
for reference and examples.