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

Limiting Page Creation based on parent


Go to End


4 Posts   4543 Views

Avatar
Krille Brocket

Community Member, 10 Posts

16 December 2009 at 12:08am

Edited: 16/12/2009 8:42pm

How can I limit the number of pages a user can create in a page of a specific type.

One of my category pages should only allow two child pages of a SPECIFIC type. I.e. The category page "Gender" should only be allowed two pages - so if a user have created the pages BOY and GIRL, they should be denied to create another "GenderPage" in the category

I tried to do something like

function canCreate() {
$child = DataObject::get("BoyPage","ParentID = ".$this->ParentID);
if($child->Count() > 1) return false;
return true;
}

but it seems like the parentID & ID fields are uninitialized

Avatar
Willr

Forum Moderator, 5523 Posts

16 December 2009 at 9:37am

Edited: 16/12/2009 8:42pm

but it seems like the parentID & ID fields are uninitialized

I think this will be because canCreate() is called before write() which populates these fields. Maybe parentID is available in $_REQUEST to use although it could be that canCreate isn't even called with on and Page object.

Avatar
Sean

Forum Moderator, 922 Posts

16 December 2009 at 8:44pm

Moving to General questions, this thread is not related to installing SS...

Avatar
Krille Brocket

Community Member, 10 Posts

16 December 2009 at 10:26pm

Edited: 17/12/2009 9:40pm