ENHANCEMENT: added AllowComments checkbox back to CMS automatically

This commit is contained in:
Will Rossiter 2010-12-13 12:33:05 +13:00
parent 500dcb8a62
commit 019e45b9ca
1 changed files with 26 additions and 5 deletions

View File

@ -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');
}
/**