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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Overriding core methods


Go to End


837 Views

Avatar
Faloude

Community Member, 55 Posts

18 December 2016 at 5:50am

Edited: 18/12/2016 6:03am

I'm trying to override the PageTypes() method in CMSMain class which populates a list of pages which can be created by the CMS user. My final goal is to change the sort of the page list which is now based on 'singular_name'. But I'm stuck at how to tell SS to use my custom method rather than the original one.

class CMSMainHook extends CMSMain {

	public function PageTypes() {

		// Get the original method return (list of pages, sorted by singular_name)
		$pages = parent::PageTypes();

		// Sort by my custom property $pos instead
		$pages->sort('post');

		// So what now?
	}
}

I've read the documentation on Injector but besides being a bit vague to me, the code just scrambles the page section of the cms so I guess either I'm not using the injector properly or my goal is not achievable using Injector.