Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Limiting Page Creation based on parent

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 3070 Views
  • Krille Brocket
    Avatar
    Community Member
    10 Posts

    Limiting Page Creation based on parent Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Limiting Page Creation based on parent Link to this post

    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.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Limiting Page Creation based on parent Link to this post

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

  • Krille Brocket
    Avatar
    Community Member
    10 Posts

    Re: Limiting Page Creation based on parent Link to this post

    3070 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.