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.

Data Model Questions

Setting a Default ParentID


Reply

3 Posts   481 Views

Avatar
zenmonkey

25 November 2012 at 1:25pm Community Member, 528 Posts

I was wondering if its possible to set the ParentID of a pagetype to specific page. The pagetype is being controlled by a ModelAdmin instead of the pages interface. I've tryed setting the $defaults array in the __construct() but I get a class does not exist error

static $defaults;   

   /**
    * Static methods
    * ----------------------------------*/
   
   public function __construct() {
      
   
      $mainListingPage = SiteTree::get_by_link("listings");
      
      
      $this->defaults = array(
         "ParentID" => $mainListingPage->ID,
      );
      
      parent::__construct();
   }

Should I just handle it in the onBeforeWrite ?

Avatar
Willr

2 December 2012 at 5:42pm Forum Moderator, 5511 Posts

Use onBeforeWrite().

Avatar
zenmonkey

11 December 2012 at 3:52am Community Member, 528 Posts

Calling it in onBefore write was failing I ended up adding a hidden ParentID field to the form and setting the value with the function. When I have a chance I'll try onBeforeWrite again so I can trackdown the actual issue.