Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Is there an elegant way to turn off comments globally


Reply

4 Posts   2298 Views

Avatar
robinp

24 February 2009 at 11:52am Community Member, 33 Posts

Hi,

Is there an elegant simple way to turn off comments in all pages and remove the comments tab from the CMS ?

Thank you

Cheers

Robin

Avatar
Anatol

6 March 2009 at 4:56pm 126 Posts

Hi Robin,

Add a few lines (in green) to /mysite/code/Page.php to the Page class:

class Page extends SiteTree {
   
   public static $db = array(
   );
   
   public static $has_one = array(
   );

   static $defaults = array(
      'ProvideComments' => false
   );
   
   function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->removeFieldFromTab("Root.Behaviour","ProvideComments");
    return $fields;
   }

}

To remove the comments tab this should work (add this to your /mysite/_config.php file):

Object::addStaticVars('LeftAndMain', array(
'removed_menu_items' => array(
      'comments'
   ),
));

I read somewhere that Silverstripe 2.3 uses

LeftAndMain::remove_menu_item('comments');


or

CMSMenu::remove_menu_item()

Not sure which one works for your version of Silverstripe.

Cheers!
Anatol

Avatar
robinp

6 March 2009 at 5:45pm Community Member, 33 Posts

Hi Anatol,

Great thank you :-)

Cheers

Robin

Avatar
ianski

14 October 2009 at 12:13pm Community Member, 2 Posts

Silverstripe 2.3.3...to remove from the main tabs...

CMSMenu::remove_menu_item('CommentAdmin');