Dear Reader,
Let me first start with the fact that I am very new to SilverStripe. Before getting myself into all kind of troubles I started of reading the Tutorials, and heard about this Module for SilverStripe by a Colleague.
It all seemed to work fine, until i wondered how to do validating with the DataObjectManager_Popup Form. Some strange things seem to happen over there! We noticed some other people asked for a solution, but from my point of view there wasn't one yet.
First post i found: link 1
Second post i found: link 2
We worked on figuring how to make it work, and voila:
class Person extends DataObject {
static $db = array(
"FirstName" => "Varchar(40)",
"LastName" => "Varchar(40)",
"Gender" => "Enum('Man, Vrouw','Man')",
"DateOfBirth" => "Date",
"Description" => "HTMLText"
);
static $has_one = array('PersonHolder' => 'PersonHolder');
public function getCMSFields_forPopup(){
$fieldSet = new FieldSet(
new TextField('FirstName', 'Voornaam','','40'),
new TextField('LastName', 'Achternaam', '','40'),
new DropdownField('Gender', 'Geslacht', array('Man', 'Vrouw')),
new CalendarDateField('DateOfBirth','Geboorte Datum'),
new HtmlEditorField('Description','Beschrijving')
);
$fieldSet->changeFieldOrder(array(
'FirstName',
'LastName',
'Gender',
'DateOfBirth',
'Description'
));
return $fieldSet;
}
}
class PersonHolder extends Page {
static $db = array();
static $has_many = array(
"Persons" => "Person"
);
public function getCMSFields(){
$oDOM = new DataObjectManager(
$this,
'Persons',
'Person',
array(
'FirstName' => 'Voornaam',
'LastName' => 'Achternaam',
'Gender' => 'Geslacht',
'DateOfBirth' => 'Geboorte Datum',
'Description' => 'Beschrijving'
),
'getCMSFields_forPopup'
);
$oDOM->popupClass = 'PersonDataObjectManager_Popup';
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Persons',
$oDOM
);
return $fields;
}
}
class PersonHolder_Controller extends Page_Controller {
}
class PersonDataObjectManager_Popup extends DataObjectManager_Popup {
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
$oVal = new RequiredFields(array('FirstName', 'LastName'));
$oVal->setForm($this);
$this->validator = $oVal;
}
}