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'
|
DELETEALLCOMMENTS: 'Delete all comments on this page'
|
||||||
SilverStripe\Comments\Admin\CommentAdmin:
|
SilverStripe\Comments\Admin\CommentAdmin:
|
||||||
ADMIN_PERMISSION: 'Access to ''Comments'' section'
|
ADMIN_PERMISSION: 'Access to ''Comments'' section'
|
||||||
ApprovedComments: Approved
|
ApprovedComments: Approved ({count})
|
||||||
Comments: Approved
|
Comments: Approved
|
||||||
MENUTITLE: Comments
|
MENUTITLE: Comments
|
||||||
Moderated: Moderated
|
Moderated: Moderated
|
||||||
NeedsModeration: 'Needs Moderation'
|
NeedsModeration: 'Needs Moderation'
|
||||||
NewComments: New
|
NewComments: New ({count})
|
||||||
SpamComments: Spam
|
SpamComments: Spam ({count})
|
||||||
SilverStripe\Comments\Admin\CommentsGridFieldAction:
|
SilverStripe\Comments\Admin\CommentsGridFieldAction:
|
||||||
APPROVE: Approve
|
APPROVE: Approve
|
||||||
COMMENTAPPROVED: 'Comment approved.'
|
COMMENTAPPROVED: 'Comment approved.'
|
||||||
|
@ -45,7 +45,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
"CMS_ACCESS_CommentAdmin" => 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')
|
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -94,34 +94,42 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
CommentsGridFieldConfig::create()
|
CommentsGridFieldConfig::create()
|
||||||
);
|
);
|
||||||
|
|
||||||
$newCount = '(' . count($newComments) . ')';
|
$fields = FieldList::create(
|
||||||
$approvedCount = '(' . count($approvedComments) . ')';
|
$root = TabSet::create(
|
||||||
$spamCount = '(' . count($spamComments) . ')';
|
'Root',
|
||||||
|
Tab::create(
|
||||||
$fields = new FieldList(
|
|
||||||
$root = new TabSet(
|
|
||||||
'Comments',
|
|
||||||
new Tab(
|
|
||||||
'NewComments',
|
'NewComments',
|
||||||
_t(__CLASS__.'.NewComments', 'New') . ' ' . $newCount,
|
_t(
|
||||||
|
__CLASS__.'.NewComments',
|
||||||
|
'New ({count})',
|
||||||
|
['count' => count($newComments)]
|
||||||
|
),
|
||||||
$newGrid
|
$newGrid
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab::create(
|
||||||
'ApprovedComments',
|
'ApprovedComments',
|
||||||
_t(__CLASS__.'.ApprovedComments', 'Approved') . ' ' . $approvedCount,
|
_t(
|
||||||
|
__CLASS__.'.ApprovedComments',
|
||||||
|
'Approved ({count})',
|
||||||
|
['count' => count($approvedComments)]
|
||||||
|
),
|
||||||
$approvedGrid
|
$approvedGrid
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab::create(
|
||||||
'SpamComments',
|
'SpamComments',
|
||||||
_t(__CLASS__.'.SpamComments', 'Spam') . ' ' . $spamCount,
|
_t(
|
||||||
|
__CLASS__.'.SpamComments',
|
||||||
|
'Spam ({count})',
|
||||||
|
['count' => count($spamComments)]
|
||||||
|
),
|
||||||
$spamGrid
|
$spamGrid
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$actions = new FieldList();
|
$actions = FieldList::create();
|
||||||
|
|
||||||
$form = new Form(
|
$form = Form::create(
|
||||||
$this,
|
$this,
|
||||||
'EditForm',
|
'EditForm',
|
||||||
$fields,
|
$fields,
|
||||||
@ -132,7 +140,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
||||||
|
|
||||||
if ($form->Fields()->hasTabset()) {
|
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());
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,20 +62,24 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
$field .= GridField_FormAction::create(
|
$field .= GridField_FormAction::create(
|
||||||
$gridField,
|
$gridField,
|
||||||
'CustomAction' . $record->ID . 'Spam',
|
'CustomAction' . $record->ID . 'Spam',
|
||||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.SPAM', 'Spam'),
|
_t(__CLASS__ . '.SPAM', 'Spam'),
|
||||||
'spam',
|
'spam',
|
||||||
array('RecordID' => $record->ID)
|
array('RecordID' => $record->ID)
|
||||||
)->Field();
|
)
|
||||||
|
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||||
|
->Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($record->IsSpam || !$record->Moderated) {
|
if ($record->IsSpam || !$record->Moderated) {
|
||||||
$field .= GridField_FormAction::create(
|
$field .= GridField_FormAction::create(
|
||||||
$gridField,
|
$gridField,
|
||||||
'CustomAction' . $record->ID . 'Approve',
|
'CustomAction' . $record->ID . 'Approve',
|
||||||
_t('SilverStripe\\Comments\\Admin\\CommentsGridFieldAction.APPROVE', 'Approve'),
|
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
||||||
'approve',
|
'approve',
|
||||||
array('RecordID' => $record->ID)
|
array('RecordID' => $record->ID)
|
||||||
)->Field();
|
)
|
||||||
|
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||||
|
->Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $field;
|
return $field;
|
||||||
@ -101,7 +105,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
// output a success message to the user
|
// output a success message to the user
|
||||||
Controller::curr()->getResponse()->setStatusCode(
|
Controller::curr()->getResponse()->setStatusCode(
|
||||||
200,
|
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
|
// output a success message to the user
|
||||||
Controller::curr()->getResponse()->setStatusCode(
|
Controller::curr()->getResponse()->setStatusCode(
|
||||||
200,
|
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\Dev\SapphireTest;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
@ -21,6 +23,10 @@ class CommentsGridFieldActionTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
|
protected static $extra_dataobjects = [
|
||||||
|
CommentableItem::class,
|
||||||
|
];
|
||||||
|
|
||||||
/** @var ArrayList */
|
/** @var ArrayList */
|
||||||
protected $list;
|
protected $list;
|
||||||
|
|
||||||
@ -30,7 +36,7 @@ class CommentsGridFieldActionTest extends SapphireTest
|
|||||||
/** @var Form */
|
/** @var Form */
|
||||||
protected $form;
|
protected $form;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->list = new DataList(Team::class);
|
$this->list = new DataList(Team::class);
|
||||||
@ -90,25 +96,26 @@ class CommentsGridFieldActionTest extends SapphireTest
|
|||||||
$recordID = $record->ID;
|
$recordID = $record->ID;
|
||||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||||
$this->assertContains('data-url="admin/comments/mockform/field/testfield', $html);
|
$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('value="Spam"', $html);
|
||||||
$this->assertContains($approveAction, $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
|
// If marked as spam, only the approve button should be available
|
||||||
$record->markSpam();
|
$record->markSpam();
|
||||||
$record->write();
|
$record->write();
|
||||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||||
$this->assertContains($approveAction, $html);
|
$this->assertContains('value="Approve"', $html);
|
||||||
$this->assertNotContains($spamAction, $html);
|
$this->assertNotContains('value="Spam"', $html);
|
||||||
|
|
||||||
// If marked as spam, only the approve button should be available
|
// If marked as spam, only the approve button should be available
|
||||||
$record->markApproved();
|
$record->markApproved();
|
||||||
$record->write();
|
$record->write();
|
||||||
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
$html = $action->getColumnContent($this->gridField, $record, Comment::class);
|
||||||
$this->assertNotContains($approveAction, $html);
|
$this->assertNotContains('value="Approve"', $html);
|
||||||
$this->assertContains($spamAction, $html);
|
$this->assertContains('value="Spam"', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetActions()
|
public function testGetActions()
|
||||||
|
Loading…
Reference in New Issue
Block a user