5093 Posts in 1516 Topics by 1113 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1241 Views |
-
How do I restrict user from creating new Pages directly under Site Content?

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 :>
-
Re: How do I restrict user from creating new Pages directly under Site Content?

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.
-
Re: How do I restrict user from creating new Pages directly under Site Content?

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();
} -
Re: How do I restrict user from creating new Pages directly under Site Content?

6 June 2010 at 11:06am
@Munhoz: Why would you put that in the onBeforeWrite method, rather than the canCreate method as willr suggested?
-
Re: How do I restrict user from creating new Pages directly under Site Content?

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.
| 1241 Views | ||
|
Page:
1
|
Go to Top |



