Skip to content

Commit

Permalink
Merge pull request #97 from arambalakjian/pulls/controller-instantiation
Browse files Browse the repository at this point in the history
API Adding config option for enabling comments to be added to SiteTree
  • Loading branch information
dhensby committed Apr 1, 2015
2 parents e576717 + 00cb672 commit 882c65f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
* consult the Commenting class.
*/

if(class_exists('SiteTree') && !Commenting::has_commenting('SiteTree')) {
if(Config::inst()->get('Commenting', 'sitetree_comments') && class_exists('SiteTree') && !Commenting::has_commenting('SiteTree')) {
Commenting::add('SiteTree');
}
}
10 changes: 8 additions & 2 deletions code/Commenting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
*/

class Commenting {

/**
* @var array map of enabled {@link DataObject} and related configuration
*/
private static $enabled_classes = array();


/**
* @config
* @var bool Whether to enable commenting on SiteTree objects by default
*/
private static $sitetree_comments = true;

/**
* @var array default configuration values
*/
Expand Down
8 changes: 4 additions & 4 deletions code/extensions/CommentsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ public function CommentsForm() {

// do not include the comments on pages which don't have id's such as security pages
if($this->owner->ID < 0) return false;
$controller = new CommentingController();

$controller = CommentingController::create();
$controller->setOwnerRecord($this->owner);
$controller->setBaseClass($this->ownerBaseClass);
$controller->setOwnerController(Controller::curr());

$moderatedSubmitted = Session::get('CommentsModerated');
Session::clear('CommentsModerated');

$form = ($enabled) ? $controller->CommentsForm() : false;

// a little bit all over the show but to ensure a slightly easier upgrade for users
// return back the same variables as previously done in comments
return $interface->process(new ArrayData(array(
Expand Down

0 comments on commit 882c65f

Please sign in to comment.