Hi,
Is there a way of being able to edit a single DataObject (in a has_one relationship) in the CMS without having to engage GridField (and changing to a has_many relation)?
I have a DataObject in SiteConfig (has_one) relationship, and would like to be able to edit it.
Example code:
DataObject
class MyImage extends DataObject
{
static $db = array (
'TitleText' => 'Text',
);
static $has_one = array (
'MyImageFile' => 'Image',
);
public function getCMSFields()
{
return new FieldList(
new TextField('TitleText'),
new UploadField('MyImageFile')
);
}
}
CustomSiteConfig.php
class CustomSiteConfig extends DataExtension{
static $db = array();
static $has_one = array(
'DefaultMyImage' => 'MyImage'
);
static $has_many = array(
);
function updateCMSFields(FieldList $fields) {
// What field do I need to include here to be able to edit a single MyImage DataObject?
return $fields;
}
}
Is it possible for some kind of field to use MyImage.getCMSFields() to generate the appropriate fields in the CMS? Or is there a way of explicitly adding each member of the DataObject to the CMS e.g.
// This doesn't seem to work...
function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.MyImage', new TextField('DefaultMyImage.TitleText', 'Title'));
$fields->addFieldToTab('Root.MyImage', new UploadField('DefaultMyImage.MyImageFile', 'My Image'));
return $fields;
}
Thanks very much.
VWD.