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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Inheriting CMSMain


Go to End


5 Posts   1951 Views

Avatar
rainerh

Community Member, 23 Posts

26 August 2009 at 11:59pm

Hello,

I want to add some further plugins to TinyMCE and some methods to CMSMain. For this reason I've created a class that inherits directly from CMSMain and overwrites some methods.
Unfortunately when the user enters the url /admin the CMSMain object is still called. I've added following command to _config.php so that SilverStripe is calling the MyMain object:

Director::addRules(60, array(
'admin/cms//$Action/$ID/$OtherID' => 'MyMain',
));

That does not work. Am I missing something???

Avatar
bummzack

Community Member, 904 Posts

27 August 2009 at 1:01am

Hm strange indeed. I never tried that.
Did you do a dev/build? Otherwise SilverStripe probably won't find the appropriate class (MyMain)

Avatar
rainerh

Community Member, 23 Posts

27 August 2009 at 5:26am

Hi there,

/dev/build doesn't help. MyMain is recognized since a rule like '/testmain' works perfectly.

Greetings!

Avatar
Mo

Community Member, 541 Posts

28 September 2009 at 1:06am

I am currently in the middle of doing this, and quite frankly its a pain in the ass!

So far I have added this to my dashboard modules _config.php file:

Director::addRules(50, array(
	'admin/dashboard'	=> 'DashboardAdmin'
));

CMSMain::$url_segment = 'cms';

CMSMenu::replace_menu_item('CMSMain', 'Site Content', 'admin/cms/', null, 10);

And added this class to extend the CMS' main menu:

class DashboardAdmin extends LeftAndMain {
	static $url_segment = '';
	
	static $menu_title = 'Dashboard';
	
	static $menu_priority = 99;
	
	static $url_priority = 41;

	/**
	 * Initialisation method called before accessing any functionality that RandomLinksAdmin has to offer
	 */
	public function init() {
		parent::init();
		
		Requirements::css('dashboard/css/Dashboard.css');
		Requirements::customScript(file_get_contents(Director::baseFolder() . '/dashboard/javascript/Dashboard.js'));
	}
	
	...

}

?>

The most important lines are:

static $url_segment = '';
static $url_priority = 41;

These basically tell Silverstripe that your new class has a higher priority than CMSMain. Please note though that url_priority can't exceed 49!

Doing this overrides the default behaviour of the CMS, but for me has caused a load of new isses, so I am now trying to extend CMSMain to fix them, I will post back when I get a result :)

Mo

Avatar
Mo

Community Member, 541 Posts

28 September 2009 at 1:29am

Not sure if you have read this, but it has some handy snippets: http://doc.silverstripe.com/doku.php?id=cmsmain