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

How to limit pages nesting level in CMS


Go to End


1151 Views

Avatar
Sewer

Community Member, 9 Posts

30 December 2011 at 3:39am

Hi all,

I need to set maximum nesting level of pages in SiteTree. For example, content manager should be able to create Page page type in SiteTree root, and as a children of pages - but it should not be possible to create pages under another pages.
I created simple function, but it doesn't work.

	public function canAddChildren($member = null) {
		if ($this->CurrentLevel() == 1) {
			return true;
		} else {
			return false;
		}
	}

I used CurrentLevel() function posted by UncleCheese here:
http://www.silverstripe.org/general-questions/show/13930

CurrentLevel works fine when used in getCMSFields(), but in canAddChildren() it always returns 1.