I am looking to make a DataObject class which injects fields into a Page object but I'm having a bit of trouble doing so. The only solutions I've found so far require me to do something within the Page (other than adding in a relationship between the two classes), I'm not all that certain as to what I'm doing wrong...
What I need would be for the DataObject to add a tab and some fields within Page and have the data for that Page to save to the DataObjects table.
In a sense I would like them to be somewhat independent of each other, so that I can link it to Article now and then some other page types at some later date.
This is what I have so far :
Article.php
class Article extends Page {
private static $description = 'An article page for writing and posting content';
private static $has_many = array(
'MyExtraFields' => 'MyExtraFields'
);
}
The DataObject
class MyExtraFields extends DataObject {
private static $db = array(
'ExtraText' => 'Varchar(255)',
'ExtraWYSIWYG' => 'HTMLText'
);
private static $has_many = array(
'Article' => 'Article'
);
private static $summary_fields = array(
'ExtraText' => 'ExtraText',
'ExtraWYSIWYG' => 'ExtraWYSIWYG'
);
public function updateCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Content.Translation', array(
TextField::create('ExtraText'),
HTMLEditorField::create('ExtraWYSIWYG')
)
);
return $fields;
}
}