Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Limiting Page Creation based on parent

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

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

Page: 1
Go to End
Author Topic: 3069 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

    3069 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.