mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #224 from creative-commoners/pulls/3.0/fix-comments-admin
FIX Duplicated tabset, invalid Pjax request, update translations and Spam/Approve buttons
This commit is contained in:
commit
3501ef7490
@ -44,13 +44,13 @@ en:
|
||||
DELETEALLCOMMENTS: 'Delete all comments on this page'
|
||||
SilverStripe\Comments\Admin\CommentAdmin:
|
||||
ADMIN_PERMISSION: 'Access to ''Comments'' section'
|
||||
ApprovedComments: Approved
|
||||
ApprovedComments: Approved ({count})
|
||||
Comments: Approved
|
||||
MENUTITLE: Comments
|
||||
Moderated: Moderated
|
||||
NeedsModeration: 'Needs Moderation'
|
||||
NewComments: New
|
||||
SpamComments: Spam
|
||||
NewComments: New ({count})
|
||||
SpamComments: Spam ({count})
|
||||
SilverStripe\Comments\Admin\CommentsGridFieldAction:
|
||||
APPROVE: Approve
|
||||
COMMENTAPPROVED: 'Comment approved.'
|
||||
|
@ -45,7 +45,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
{
|
||||
return array(
|
||||
"CMS_ACCESS_CommentAdmin" => array(
|
||||
'name' => _t('SilverStripe\\Comments\\Admin\\CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
||||
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
||||
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
||||
)
|
||||
);
|
||||
@ -94,34 +94,42 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
CommentsGridFieldConfig::create()
|
||||
);
|
||||
|
||||
$newCount = '(' . count($newComments) . ')';
|
||||
$approvedCount = '(' . count($approvedComments) . ')';
|
||||
$spamCount = '(' . count($spamComments) . ')';
|
||||
|
||||
$fields = new FieldList(
|
||||
$root = new TabSet(
|
||||
'Comments',
|
||||
new Tab(
|
||||
$fields = FieldList::create(
|
||||
$root = TabSet::create(
|
||||
'Root',
|
||||
Tab::create(
|
||||
'NewComments',
|
||||
_t(__CLASS__.'.NewComments', 'New') . ' ' . $newCount,
|
||||
_t(
|
||||
__CLASS__.'.NewComments',
|
||||
'New ({count})',
|
||||
['count' => count($newComments)]
|
||||
),
|
||||
$newGrid
|
||||
),
|
||||
new Tab(
|
||||
Tab::create(
|
||||
'ApprovedComments',
|
||||
_t(__CLASS__.'.ApprovedComments', 'Approved') . ' ' . $approvedCount,
|
||||
_t(
|
||||
__CLASS__.'.ApprovedComments',
|
||||
'Approved ({count})',
|
||||
['count' => count($approvedComments)]
|
||||
),
|
||||
$approvedGrid
|
||||
),
|
||||
new Tab(
|
||||
Tab::create(
|
||||
'SpamComments',
|
||||
_t(__CLASS__.'.SpamComments', 'Spam') . ' ' . $spamCount,
|
||||
_t(
|
||||
__CLASS__.'.SpamComments',
|
||||
'Spam ({count})',
|
||||
['count' => count($spamComments)]
|
||||
),
|
||||
$spamGrid
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$actions = new FieldList();
|
||||
$actions = FieldList::create();
|
||||
|
||||
$form = new Form(
|
||||
$form = Form::create(
|
||||
$this,
|
||||
'EditForm',
|
||||
$fields,
|
||||
@ -132,7 +140,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
||||
|
||||
if ($form->Fields()->hasTabset()) {
|
||||
// $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
||||
$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet');
|
||||
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
|
||||
}
|
||||
|
||||
|
@ -62,20 +62,24 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID . 'Spam',
|
||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.SPAM', 'Spam'),
|
||||
_t(__CLASS__ . '.SPAM', 'Spam'),
|
||||
'spam',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
)
|
||||
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||
->Field();
|
||||
}
|
||||
|
||||
if ($record->IsSpam || !$record->Moderated) {
|
||||
$field .= GridField_FormAction::create(
|
||||
$gridField,
|
||||
'CustomAction' . $record->ID . 'Approve',
|
||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.APPROVE', 'Approve'),
|
||||
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
||||
'approve',
|
||||
array('RecordID' => $record->ID)
|
||||
)->Field();
|
||||
)
|
||||
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||
->Field();
|
||||
}
|
||||
|
||||
return $field;
|
||||
@ -101,7 +105,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
// output a success message to the user
|
||||
Controller::curr()->getResponse()->setStatusCode(
|
||||
200,
|
||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.COMMENTMARKEDSPAM', 'Comment marked as spam.')
|
||||
_t(__CLASS__ . '.COMMENTMARKEDSPAM', 'Comment marked as spam.')
|
||||
);
|
||||
}
|
||||
|
||||
@ -112,7 +116,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
// output a success message to the user
|
||||
Controller::curr()->getResponse()->setStatusCode(
|
||||
200,
|
||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.COMMENTAPPROVED', 'Comment approved.')
|
||||
_t(__CLASS__ . '.COMMENTAPPROVED', 'Comment approved.')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,10 @@ use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
@ -21,6 +23,10 @@ class CommentsGridFieldActionTest extends SapphireTest
|
||||
{
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected static $extra_dataobjects = [
|
||||
CommentableItem::class,
|
||||
];
|
||||
|
||||
/** @var ArrayList */
|
||||
protected $list;
|
||||
|
||||
@ -30,7 +36,7 @@ class CommentsGridFieldActionTest extends SapphireTest
|
||||
/** @var Form */
|
||||
protected $form;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->list = new DataList(Team::class);
|
||||
@ -90,25 +96,26 @@ class CommentsGridFieldActionTest extends SapphireTest
|
||||
$recordID = $record->ID;
|
||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||
$this->assertContains('data-url="admin/comments/mockform/field/testfield', $html);
|
||||
$spamAction = 'value="Spam" class="action" id="action_CustomAction' . $recordID . 'Spam"';
|
||||
$this->assertContains($spamAction, $html);
|
||||
|
||||
$approveAction = 'value="Approve" class="action" id="action_CustomAction' . $recordID . 'Approve"';
|
||||
$this->assertContains($approveAction, $html);
|
||||
$this->assertContains('value="Spam"', $html);
|
||||
$this->assertContains('id="action_CustomAction' . $recordID . 'Spam"', $html);
|
||||
|
||||
$this->assertContains('value="Approve"', $html);
|
||||
$this->assertContains('id="action_CustomAction' . $recordID . 'Approve"', $html);
|
||||
|
||||
// If marked as spam, only the approve button should be available
|
||||
$record->markSpam();
|
||||
$record->write();
|
||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||
$this->assertContains($approveAction, $html);
|
||||
$this->assertNotContains($spamAction, $html);
|
||||
$this->assertContains('value="Approve"', $html);
|
||||
$this->assertNotContains('value="Spam"', $html);
|
||||
|
||||
// If marked as spam, only the approve button should be available
|
||||
$record->markApproved();
|
||||
$record->write();
|
||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||
$this->assertNotContains($approveAction, $html);
|
||||
$this->assertContains($spamAction, $html);
|
||||
$this->assertNotContains('value="Approve"', $html);
|
||||
$this->assertContains('value="Spam"', $html);
|
||||
}
|
||||
|
||||
public function testGetActions()
|
||||
|
Loading…
Reference in New Issue
Block a user