/
UnlinkHandler.php
114 lines (100 loc) · 2.65 KB
/
UnlinkHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Colymba\BulkManager\BulkAction;
use Colymba\BulkManager\BulkAction\Handler;
use Colymba\BulkTools\HTTPBulkToolsResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use Exception;
/**
* Bulk action handler for unlinking records.
*
* @author colymba
*/
class UnlinkHandler extends Handler
{
/**
* URL segment used to call this handler
* If none given, @BulkManager will fallback to the Unqualified class name
*
* @var string
*/
private static $url_segment = 'unlink';
/**
* RequestHandler allowed actions.
*
* @var array
*/
private static $allowed_actions = array('unLink');
/**
* RequestHandler url => action map.
*
* @var array
*/
private static $url_handlers = array(
'' => 'unLink',
);
/**
* Front-end label for this handler's action
*
* @var string
*/
protected $label = 'Unlink';
/**
* Front-end icon path for this handler's action.
*
* @var string
*/
protected $icon = '';
/**
* Extra classes to add to the bulk action button for this handler
* Can also be used to set the button font-icon e.g. font-icon-trash
*
* @var string
*/
protected $buttonClasses = 'font-icon-link-broken';
/**
* Whether this handler should be called via an XHR from the front-end
*
* @var boolean
*/
protected $xhr = true;
/**
* Set to true is this handler will destroy any data.
* A warning and confirmation will be shown on the front-end.
*
* @var boolean
*/
protected $destructive = false;
/**
* Return i18n localized front-end label
*
* @return array
*/
public function getI18nLabel()
{
return _t('GRIDFIELD_BULK_MANAGER.UNLINK_SELECT_LABEL', $this->getLabel());
}
/**
* Unlink the selected records passed from the unlink bulk action.
*
* @param HTTPRequest $request
*
* @return HTTPBulkToolsResponse
*/
public function unLink(HTTPRequest $request)
{
$ids = $this->getRecordIDList();
$response = new HTTPBulkToolsResponse(true, $this->gridField);
try {
//@todo fix this. seems no ids are returned!
$response->addSuccessRecords($this->getRecords());
$this->gridField->list->removeMany($ids);
$response->setMessage('UnLinked records.');
} catch (Exception $ex) {
$response->setStatusCode(500);
$response->setMessage($ex->getMessage());
}
return $response;
}
}