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.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Limiting Page Creation based on parent


Reply

4 Posts   3095 Views

Avatar
Krille Brocket

16 December 2009 at 12:08am (Last edited: 16 December 2009 8:42pm), Community Member, 10 Posts

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

16 December 2009 at 9:37am (Last edited: 16 December 2009 8:42pm), Forum Moderator, 5511 Posts

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

16 December 2009 at 8:44pm Forum Moderator, 921 Posts

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

Avatar
Krille Brocket

16 December 2009 at 10:26pm (Last edited: 17 December 2009 9:40pm), Community Member, 10 Posts