From 192ddbb4b5f3c27598e92b40489c4ffdd0f90b1b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 26 Feb 2018 12:33:08 +1300 Subject: [PATCH] API Use concrete Handler implementations for Spam and Approve bulk editing --- .../ApproveHandler.php | 49 +++++++++++++ .../CommentsGridFieldBulkAction/Handler.php | 72 ------------------- .../SpamHandler.php | 49 +++++++++++++ src/Admin/CommentsGridFieldConfig.php | 33 +++------ 4 files changed, 106 insertions(+), 97 deletions(-) create mode 100644 src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php delete mode 100644 src/Admin/CommentsGridFieldBulkAction/Handler.php create mode 100644 src/Admin/CommentsGridFieldBulkAction/SpamHandler.php diff --git a/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php b/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php new file mode 100644 index 0000000..6e7506f --- /dev/null +++ b/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php @@ -0,0 +1,49 @@ +getRecords() as $record) { + array_push($ids, $record->ID); + $record->markApproved(); + } + + $response = new HTTPResponse(Convert::raw2json([ + 'done' => true, + 'records' => $ids, + ])); + + $response->addHeader('Content-Type', 'text/json'); + + return $response; + } +} diff --git a/src/Admin/CommentsGridFieldBulkAction/Handler.php b/src/Admin/CommentsGridFieldBulkAction/Handler.php deleted file mode 100644 index 407872e..0000000 --- a/src/Admin/CommentsGridFieldBulkAction/Handler.php +++ /dev/null @@ -1,72 +0,0 @@ - 'spam', - 'approve' => 'approve', - ); - - /** - * @param HTTPRequest $request - * @return HTTPResponse - */ - public function spam(HTTPRequest $request) - { - $ids = array(); - - foreach ($this->getRecords() as $record) { - array_push($ids, $record->ID); - $record->markSpam(); - } - - $response = new HTTPResponse(Convert::raw2json(array( - 'done' => true, - 'records' => $ids - ))); - - $response->addHeader('Content-Type', 'text/json'); - - return $response; - } - - /** - * @param HTTPRequest $request - * @return HTTPResponse - */ - public function approve(HTTPRequest $request) - { - $ids = array(); - - foreach ($this->getRecords() as $record) { - array_push($ids, $record->ID); - $record->markApproved(); - } - - $response = new HTTPResponse(Convert::raw2json(array( - 'done' => true, - 'records' => $ids - ))); - - $response->addHeader('Content-Type', 'text/json'); - - return $response; - } -} diff --git a/src/Admin/CommentsGridFieldBulkAction/SpamHandler.php b/src/Admin/CommentsGridFieldBulkAction/SpamHandler.php new file mode 100644 index 0000000..8c6421b --- /dev/null +++ b/src/Admin/CommentsGridFieldBulkAction/SpamHandler.php @@ -0,0 +1,49 @@ +getRecords() as $record) { + array_push($ids, $record->ID); + $record->markSpam(); + } + + $response = new HTTPResponse(Convert::raw2json([ + 'done' => true, + 'records' => $ids, + ])); + + $response->addHeader('Content-Type', 'text/json'); + + return $response; + } +} diff --git a/src/Admin/CommentsGridFieldConfig.php b/src/Admin/CommentsGridFieldConfig.php index 51f3274..4225fec 100644 --- a/src/Admin/CommentsGridFieldConfig.php +++ b/src/Admin/CommentsGridFieldConfig.php @@ -3,7 +3,8 @@ namespace SilverStripe\Comments\Admin; use Colymba\BulkManager\BulkManager; -use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handler; +use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler; +use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler; use SilverStripe\Core\Convert; use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; use SilverStripe\Forms\GridField\GridFieldDataColumns; @@ -31,32 +32,14 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor )); // Add bulk option - $manager = new BulkManager(); + $manager = new BulkManager(null, false); - $manager->addBulkAction( - 'spam', - _t(__CLASS__ . '.SPAM', 'Spam'), - Handler::class, - array( - 'isAjax' => true, - 'icon' => 'cross', - 'isDestructive' => false - ) - ); + $spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam')); + $approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve')); - $manager->addBulkAction( - 'approve', - _t(__CLASS__ . '.APPROVE', 'Approve'), - Handler::class, - array( - 'isAjax' => true, - 'icon' => 'cross', - 'isDestructive' => false - ) - ); - - $manager->removeBulkAction('bulkEdit'); - $manager->removeBulkAction('unLink'); + $manager + ->addBulkAction($spamAction) + ->addBulkAction($approveAction); $this->addComponent($manager); }