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   3219 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, 5513 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