21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1122 Views |
-
populateDefaults method on a Page object

30 March 2010 at 10:28pm Last edited: 30 March 2010 10:28pm
I'm trying to force populateDefaults method on an extended Page object, but it does not work, is this only working on a
DataObject?public function populateDefaults() {
parent::populateDefaults();
$this->Title = 'ForcedTitle';}
-
Re: populateDefaults method on a Page object

1 April 2010 at 12:50pm
Hi Bartvanirsel,
This function does work on any page class, however the reason it isnt working on the Title field is because I believe there is some JS which runs to set the default page title which would override this.
Try setting another field to see if that works, if it does then obiusly there is some funny stuff going on to generate the default title and you may have to look deeper to override it.
Hope that helps.
Aram
www.ssbits.com - SilverStripe tutorials, tips and other bits
-
Re: populateDefaults method on a Page object

2 April 2010 at 12:49am Last edited: 2 April 2010 12:59am
I can confirm this is not working for Page Titles.
However this does the trick for me:
function populateDefaults() {
parent::populateDefaults();
$this->Title = _t('Page.TITLE', "My translated title");
}
function onBeforeWrite() {
parent::onBeforeWrite();
if($this->Status == 'New page'){
$this->populateDefaults();
}
}Edit:
You could also check by version:
if($this->Version == 0){
$this->populateDefaults();
} -
Re: populateDefaults method on a Page object

2 April 2010 at 3:41am
Hey Martijn,
checking on $this->Version worked! thanks
| 1122 Views | ||
|
Page:
1
|
Go to Top |



