GridFieldBulkEditingTools/src/BulkManager/BulkAction/UnlinkHandler.php

54 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Colymba\BulkManager\BulkAction;
use Colymba\BulkManager\BulkAction\Handler;
use SilverStripe\Core\Convert;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
/**
2014-05-04 16:12:05 +02:00
* Bulk action handler for unlinking records.
*
* @author colymba
*/
class UnlinkHandler extends Handler
{
2015-12-15 13:08:57 +01:00
/**
* RequestHandler allowed actions.
*
* @var array
*/
private static $allowed_actions = array('unLink');
2015-12-15 13:08:57 +01:00
/**
* RequestHandler url => action map.
*
* @var array
*/
private static $url_handlers = array(
'unLink' => 'unLink',
);
2014-05-11 12:32:21 +02:00
2015-12-15 13:08:57 +01:00
/**
* Unlink the selected records passed from the unlink bulk action.
*
* @param HTTPRequest $request
*
* @return HTTPResponse List of affected records ID
2015-12-15 13:08:57 +01:00
*/
public function unLink(HTTPRequest $request)
2015-12-15 13:08:57 +01:00
{
$ids = $this->getRecordIDList();
$this->gridField->list->removeMany($ids);
$response = new HTTPResponse(Convert::raw2json(array(
2015-12-15 13:08:57 +01:00
'done' => true,
'records' => $ids,
)));
$response->addHeader('Content-Type', 'text/json');
return $response;
}
}