GridFieldBulkEditingTools/docs/en/BULK_MANAGER.md

48 lines
2.2 KiB
Markdown
Raw Normal View History

2013-12-05 18:42:17 +01:00
# Bulk Manager
2014-05-04 17:13:03 +02:00
Perform actions on multiple records straight from the GridField. Comes with *unlink*, *delete* and bulk *editing*. You can also easily create/add your own.
2013-12-05 18:42:17 +01:00
## Usage
2014-05-04 17:13:03 +02:00
Simply add component to your `GridFieldConfig`
```php
$config->addComponent(new \Colymba\BulkManager\BulkManager());
```
2013-12-05 18:42:17 +01:00
## Configuration
2014-05-04 17:13:03 +02:00
The component's options can be configurated individually or in bulk through the 'config' functions like this:
2013-12-05 18:42:17 +01:00
```php
$config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($reference, $value);
```
2013-12-05 18:42:17 +01:00
### $config overview
The available configuration options are:
* 'editableFields' : array of string referencing specific CMS fields available for editing
## 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:
```php
$config
->getComponentByType('Colymba\\BulkManager\\BulkManager')
->addBulkAction('actionName', 'Dropdown label', 'ActionHandlerClassName', $frontEndConfig)
```
2013-12-05 18:42:17 +01:00
You can omit the handler's class name and the front-end config array, those will default to:
* `'GridFieldBulkAction'.ucfirst($name).'Handler'`
* `$config = array( 'isAjax' => true, 'icon' => 'accept', 'isDestructive' => false )`
#### 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.
2013-12-05 18:42:17 +01:00
Make sure to define your `$allowed_actions` and `$url_handlers` on your custom bulk action handler. See `Handler`, `DeleteHandler` and `UnlinkHandler` for examples.
2013-12-05 18:42:17 +01:00
#### Front-end config
2014-05-04 17:13:03 +02:00
The last `addBulkAction()` parameter lets you pass an array with configuration options for the UI/UX:
* `isAjax`: if true the action will be called via XHR request otherwise the browser will be redirected to the action's URL
* `icon`: lets you define which icon to use on the button when the action is selected (SilverStripe button icon name only)
* `isDestructive`: if true, a confirmation dialog will be shown before the action is processed