Using the standard scaffolding, how would you do about setting default values for fields in a DataObject's form?
I have tried this, but it does not seem to work:
class Employee extends DataObject {
...
function getCMSFields()
{
$fields = parent::getCMSFields();
if (!$this->ID) {
// New record: set dynamic defaults.
$fields->setValues(array(
'StartDate' => date('Y/m/d'),
'EmployeeNumber' => $this->getNextEmployeeNumber(),
));
}
return $fields;
}
}
I was expecting the setValues() method to set the values of the fields before being presented on the new item form, but they are not. That section of code *is* executed though.
Any idea what could be going wrong, or how to set default values for DataObject fields that are not simple static values?
-- Jason