mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-06-18 10:41:37 +02:00
Previous versions had individual spam and approve buttons for a comment in the admin area on the GridField row. However with the upgrade to SilverStripe 4, and particularly 4.2, these were having layout issues with the new GridField Action Menu component that groups actions together. The solution here is to put them into aforementioned gridfield action menu component, with the other actions for that row. However this requires two separate grid field components (one each for the two comment actions) - previously these were a single component that output two buttons instead of one each. This also reduces coupling, which is nice :) The previous class is still maintained for backwards compatibilty, but is deprecated.
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?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;
|
|
|
|
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
|
{
|
|
public function __construct($itemsPerPage = 25)
|
|
{
|
|
parent::__construct($itemsPerPage);
|
|
|
|
// $this->addComponent(new GridFieldExportButton());
|
|
|
|
$this->addComponents([
|
|
new CommentsGridFieldSpamAction(),
|
|
new CommentsGridFieldApproveAction(),
|
|
]);
|
|
|
|
// Format column
|
|
/** @var GridFieldDataColumns $columns */
|
|
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
|
$columns->setFieldFormatting([
|
|
'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()
|
|
);
|
|
}
|
|
]);
|
|
|
|
// 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);
|
|
|
|
$this->addComponent($manager);
|
|
}
|
|
}
|