diff --git a/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php b/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php new file mode 100644 index 0000000..7d31015 --- /dev/null +++ b/src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php @@ -0,0 +1,28 @@ +markApproved(); + return $comment; + } +} diff --git a/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php new file mode 100644 index 0000000..b22d04f --- /dev/null +++ b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php @@ -0,0 +1,46 @@ +getRecords() as $comment) { + array_push($ids, $comment->ID); + $this->updateComment($comment); + } + + $response = new HTTPResponse(Convert::raw2json([ + 'done' => true, + 'records' => $ids, + ])); + + $response->addHeader('Content-Type', 'application/json'); + + return $response; + } + + /** + * @param Comment $comment + * + * @return Comment + */ + abstract public function updateComment($comment); +} 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..991649c --- /dev/null +++ b/src/Admin/CommentsGridFieldBulkAction/SpamHandler.php @@ -0,0 +1,28 @@ +markSpam(); + return $comment; + } +} 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); }