mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
ENHANCEMENT: added AllowComments checkbox back to CMS automatically
This commit is contained in:
parent
500dcb8a62
commit
019e45b9ca
@ -15,7 +15,7 @@ class CommentsExtension extends DataObjectDecorator {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function extraStatics() {
|
||||
public function extraStatics() {
|
||||
$fields = array();
|
||||
|
||||
$relationships = array(
|
||||
@ -41,6 +41,23 @@ class CommentsExtension extends DataObjectDecorator {
|
||||
return array_merge($fields, $relationships);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this extension is applied to a {@link SiteTree} record then
|
||||
* append a Provide Comments checkbox to allow authors to trigger
|
||||
* whether or not to display comments
|
||||
*
|
||||
* @todo Allow customization of other {@link Commenting} configuration
|
||||
*
|
||||
* @param FieldSet
|
||||
*/
|
||||
public function updateCMSFields(&$fields) {
|
||||
if($this->attachedToSiteTree()) {
|
||||
$fields->addFieldToTab('Root.Behaviour',
|
||||
new CheckboxField('ProvideComments', _t('Comment.ALLOWCOMMENTS', 'Allow Comments'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the comments attached to this record.
|
||||
*
|
||||
@ -48,11 +65,13 @@ class CommentsExtension extends DataObjectDecorator {
|
||||
*
|
||||
* @return DataObjectSet
|
||||
*/
|
||||
function Comments() {
|
||||
public function Comments() {
|
||||
$order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by');
|
||||
|
||||
return DataObject::get(
|
||||
'Comment',
|
||||
"\"ParentID\" = '". $this->owner->ID ."' AND \"BaseClass\" = '". $this->ownerBaseClass ."'",
|
||||
Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by')
|
||||
$order
|
||||
);
|
||||
}
|
||||
|
||||
@ -81,7 +100,7 @@ class CommentsExtension extends DataObjectDecorator {
|
||||
|
||||
$controller = new CommentingController();
|
||||
|
||||
// tad bit messy but needed to ensure all datas available
|
||||
// tad bit messy but needed to ensure all data is available
|
||||
$controller->setOwnerRecord($this->owner);
|
||||
$controller->setBaseClass($this->ownerBaseClass);
|
||||
$controller->setOwnerController(Controller::curr());
|
||||
@ -106,7 +125,9 @@ class CommentsExtension extends DataObjectDecorator {
|
||||
* @return bool
|
||||
*/
|
||||
public function attachedToSiteTree() {
|
||||
return ClassInfo::is_subclass_of($this->ownerBaseClass, 'SiteTree');
|
||||
$class = $this->ownerBaseClass;
|
||||
|
||||
return (ClassInfo::is_subclass_of($class, 'SiteTree')) || ($class == 'SiteTree');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user