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

How do I restrict user from creating new Pages directly under Site Content?


Go to End


5 Posts   1972 Views

Avatar
overboming

Community Member, 2 Posts

31 August 2009 at 3:41am

I mean, it's possible for locations at other levels because I can override the canCreate method of that specific container page type.
But if directly under Site Content. There is no way for me to restrict user creating pages there. If a user can create a certain page type, then he can create as many instances as he wants along with the Home page and the 404 page.
Is there anyway I can solve this?

Thanks :>

Avatar
Willr

Forum Moderator, 5523 Posts

31 August 2009 at 9:15am

But if directly under Site Content...

Can you override canCreate() on the main Page.php file? I would have thought if you defined a function on that it would work for all the levels.

Avatar
Munhoz

Community Member, 3 Posts

6 June 2010 at 3:50am

Try this code in pages.php, it allows page creation under Site Content only for Administrators...

public function onBeforeWrite() {
if(!Permission::check('ADMIN')){
if (!$this->ParentID) {
user_error('Cannot create new page at top level', E_USER_ERROR);
exit();
}
}
parent::onBeforeWrite();
}

Avatar
dhensby

Community Member, 253 Posts

6 June 2010 at 11:06am

@Munhoz: Why would you put that in the onBeforeWrite method, rather than the canCreate method as willr suggested?

Avatar
Munhoz

Community Member, 3 Posts

6 June 2010 at 11:22am

I was unable to find the 'ParentID' field of the new page, or another way to check the page level, in the CanCreate method.
Then i created this code from different code examples and it worked!

Ps. I am a newbie in SilverStripe, dont know much about the programming part.