I am trying to add a Checkbox field to the CMS (Page Class) and having no luck in setting it to be checked by default. My code is below.
class Page extends SiteTree {
public static $db = array(
'TemplateStyle' => 'Enum("Blue,Brown,Green,Orange,Home")',
'ShowInGoogleSiteMap' => 'Boolean'
);
public static $has_one = array(
);
static $defaults = array(
"ShowInGoogleSiteMap" => 1
);
/******************************************
* Add fields to CMS
*******************************************/
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Behaviour', new CheckboxField('ShowInGoogleSiteMap','Show in Google SiteMap?'),'ProvideComments');
return $fields;
}
Attempted Solutions:
1. I have tried adding a default value as a parameter like the following. But this does not work - nor does it look like this is a parameter in the API doc.
$fields->addFieldToTab('Root.Behaviour', new CheckboxField('ShowInGoogleSiteMap','Show in Google SiteMap?'),'ProvideComments');
2. I have also tried adding this to the Page Class as well. But this does not work either.
public function populateDefaults(){
parent::populateDefaults();
$this->ShowInGoogleSiteMap = 1;
}
Anyone know how to make this work?
Thanks