mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
NEW relocate spam and approve admin actions
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.
This commit is contained in:
parent
f5c7024aaf
commit
b6a2c608ac
10
.travis.yml
10
.travis.yml
@ -4,12 +4,14 @@ dist: trusty
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||||
- php: 7.0
|
- php: 7.0
|
||||||
env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1
|
env: DB=PGSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_TEST=1
|
||||||
- php: 7.1
|
- php: 7.1
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_COVERAGE_TEST=1
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
|
env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_TEST=1
|
||||||
|
- php: 7.3
|
||||||
env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1
|
env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
@ -17,7 +19,7 @@ before_script:
|
|||||||
- phpenv config-rm xdebug.ini
|
- phpenv config-rm xdebug.ini
|
||||||
- composer validate
|
- composer validate
|
||||||
- composer require silverstripe/installer:"$INSTALLER_VERSION" ezyang/htmlpurifier:* --no-update
|
- composer require silverstripe/installer:"$INSTALLER_VERSION" ezyang/htmlpurifier:* --no-update
|
||||||
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
|
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev; fi
|
||||||
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/framework": "^4.0",
|
"silverstripe/framework": "^4.2",
|
||||||
"colymba/gridfield-bulk-editing-tools": "^3.0"
|
"colymba/gridfield-bulk-editing-tools": "^3.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
@ -9,6 +9,9 @@ use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
|||||||
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
||||||
use SilverStripe\Forms\GridField\GridField_FormAction;
|
use SilverStripe\Forms\GridField\GridField_FormAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 3.2.0 {@see CommentsGridFieldApproveAction} and {@see CommentsGridFieldSpamAction} instead
|
||||||
|
*/
|
||||||
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider
|
class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
140
src/Admin/CommentsGridFieldApproveAction.php
Normal file
140
src/Admin/CommentsGridFieldApproveAction.php
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Comments\Admin;
|
||||||
|
|
||||||
|
use SilverStripe\Comments\Model\Comment;
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ActionMenuItem;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_FormAction;
|
||||||
|
|
||||||
|
class CommentsGridFieldApproveAction implements
|
||||||
|
GridField_ColumnProvider,
|
||||||
|
GridField_ActionProvider,
|
||||||
|
GridField_ActionMenuItem
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function augmentColumns($gridField, &$columns)
|
||||||
|
{
|
||||||
|
if (!in_array('Actions', $columns)) {
|
||||||
|
$columns[] = 'Actions';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
return _t(__CLASS__ . '.APPROVE', 'Approve');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtraData($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
|
||||||
|
$field = $this->getApproveAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
if ($field) {
|
||||||
|
return $field->getAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public function getGroup($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
$field = $this->getApproveAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
return $field ? GridField_ActionMenuItem::DEFAULT_GROUP: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnAttributes($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
return ['class' => 'col-buttons grid-field__col-compact'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnMetadata($gridField, $columnName)
|
||||||
|
{
|
||||||
|
if ($columnName === 'Actions') {
|
||||||
|
return ['title' => ''];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnsHandled($gridField)
|
||||||
|
{
|
||||||
|
return ['Actions'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnContent($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
if (!$record->canEdit()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$field = $this->getApproveAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
return $field ? $field->Field() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the FormAction object, used by other methods to get properties
|
||||||
|
*
|
||||||
|
* @return GridField_FormAction
|
||||||
|
*/
|
||||||
|
public function getApproveAction($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
$field = GridField_FormAction::create(
|
||||||
|
$gridField,
|
||||||
|
'CustomAction' . $record->ID . 'Approve',
|
||||||
|
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
||||||
|
'approve',
|
||||||
|
['RecordID' => $record->ID]
|
||||||
|
)
|
||||||
|
->addExtraClass(implode(' ', [
|
||||||
|
'btn',
|
||||||
|
'btn-secondary',
|
||||||
|
'grid-field__icon-action',
|
||||||
|
'action-menu--handled',
|
||||||
|
'font-icon-check-mark',
|
||||||
|
]))
|
||||||
|
->setAttribute('classNames', 'font-icon-check-mark');
|
||||||
|
|
||||||
|
return ($record->IsSpam || !$record->Moderated) ? $field : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getActions($gridField)
|
||||||
|
{
|
||||||
|
return ['approve'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||||
|
{
|
||||||
|
/** @var Comment $comment */
|
||||||
|
$comment = Comment::get()->byID($arguments['RecordID']);
|
||||||
|
$comment->markApproved();
|
||||||
|
|
||||||
|
// output a success message to the user
|
||||||
|
Controller::curr()->getResponse()->setStatusCode(
|
||||||
|
200,
|
||||||
|
_t(__CLASS__ . '.COMMENTAPPROVED', 'Comment approved.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ use Colymba\BulkManager\BulkManager;
|
|||||||
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
|
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
|
||||||
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
|
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ActionMenu;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
|
|
||||||
@ -17,7 +18,10 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
|||||||
|
|
||||||
// $this->addComponent(new GridFieldExportButton());
|
// $this->addComponent(new GridFieldExportButton());
|
||||||
|
|
||||||
$this->addComponent(new CommentsGridFieldAction());
|
$this->addComponents([
|
||||||
|
new CommentsGridFieldSpamAction(),
|
||||||
|
new CommentsGridFieldApproveAction(),
|
||||||
|
]);
|
||||||
|
|
||||||
// Format column
|
// Format column
|
||||||
/** @var GridFieldDataColumns $columns */
|
/** @var GridFieldDataColumns $columns */
|
||||||
|
141
src/Admin/CommentsGridFieldSpamAction.php
Normal file
141
src/Admin/CommentsGridFieldSpamAction.php
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Comments\Admin;
|
||||||
|
|
||||||
|
use SilverStripe\Comments\Model\Comment;
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ActionMenuItem;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_FormAction;
|
||||||
|
|
||||||
|
class CommentsGridFieldSpamAction implements
|
||||||
|
GridField_ColumnProvider,
|
||||||
|
GridField_ActionProvider,
|
||||||
|
GridField_ActionMenuItem
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function augmentColumns($gridField, &$columns)
|
||||||
|
{
|
||||||
|
if (!in_array('Actions', $columns)) {
|
||||||
|
$columns[] = 'Actions';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
return _t(__CLASS__ . '.SPAM', 'Spam');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtraData($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
|
||||||
|
$field = $this->getSpamAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
if ($field) {
|
||||||
|
return $field->getAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroup($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
$field = $this->getSpamAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
return $field ? GridField_ActionMenuItem::DEFAULT_GROUP: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnAttributes($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
return ['class' => 'col-buttons grid-field__col-compact'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnMetadata($gridField, $columnName)
|
||||||
|
{
|
||||||
|
if ($columnName === 'Actions') {
|
||||||
|
return ['title' => ''];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnsHandled($gridField)
|
||||||
|
{
|
||||||
|
return ['Actions'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getColumnContent($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
if (!$record->canEdit()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$field = $this->getSpamAction($gridField, $record, $columnName);
|
||||||
|
|
||||||
|
return $field ? $field->Field() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the FormAction object, used by other methods to get properties
|
||||||
|
*
|
||||||
|
* @return GridField_FormAction
|
||||||
|
*/
|
||||||
|
public function getSpamAction($gridField, $record, $columnName)
|
||||||
|
{
|
||||||
|
$field = GridField_FormAction::create(
|
||||||
|
$gridField,
|
||||||
|
'CustomAction' . $record->ID . 'Spam',
|
||||||
|
_t(__CLASS__ . '.SPAM', 'Spam'),
|
||||||
|
'spam',
|
||||||
|
['RecordID' => $record->ID]
|
||||||
|
)
|
||||||
|
->addExtraClass(implode(' ', [
|
||||||
|
'btn',
|
||||||
|
'btn-secondary',
|
||||||
|
'grid-field__icon-action',
|
||||||
|
'action-menu--handled',
|
||||||
|
'font-icon-cross-mark',
|
||||||
|
]))
|
||||||
|
->setAttribute('classNames', 'font-icon-cross-mark');
|
||||||
|
return (!$record->IsSpam || !$record->Moderated) ? $field : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getActions($gridField)
|
||||||
|
{
|
||||||
|
return ['spam'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||||
|
{
|
||||||
|
/** @var Comment $comment */
|
||||||
|
$comment = Comment::get()->byID($arguments['RecordID']);
|
||||||
|
$comment->markSpam();
|
||||||
|
|
||||||
|
// output a success message to the user
|
||||||
|
Controller::curr()->getResponse()->setStatusCode(
|
||||||
|
200,
|
||||||
|
_t(__CLASS__ . '.COMMENTMARKEDSPAM', 'Comment marked as spam.')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user