silverstripe-comments/src/Admin/CommentsGridFieldConfig.php

52 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Comments\Admin;
use Colymba\BulkManager\BulkManager;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridField_ActionMenu;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
2016-02-19 01:48:25 +01:00
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
{
public function __construct($itemsPerPage = 25)
{
parent::__construct($itemsPerPage);
// $this->addComponent(new GridFieldExportButton());
$this->addComponents([
new CommentsGridFieldSpamAction(),
new CommentsGridFieldApproveAction(),
]);
2016-02-19 01:48:25 +01:00
// Format column
/** @var GridFieldDataColumns $columns */
$columns = $this->getComponentByType(GridFieldDataColumns::class);
$columns->setFieldFormatting([
2016-02-19 01:48:25 +01:00
'ParentTitle' => function ($value, &$item) {
return sprintf(
'<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
Convert::raw2att($item->Link()),
$item->obj('ParentTitle')->forTemplate()
);
}
]);
2016-02-19 01:48:25 +01:00
// Add bulk option
$manager = BulkManager::create(null, false);
$spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
$approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
$manager
->addBulkAction($spamAction)
->addBulkAction($approveAction);
2016-02-19 01:48:25 +01:00
$this->addComponent($manager);
}
}