I am building a service comparison chart that sits on a ServiceComparisonPage type. The data objects aren't necessarily linked to the page type but as there will be only one of these charts in the site, it will make it easier for the user to edit it here.
I have managed to use the DataObjectManager to build a new tab for each dataobject and allow management of objects. The problem I am having is that I want each service object to be able to link to any page in the site however because the management of data objects is on a Page class, the LinkToID field is hidden on the pop up form and set to the page that it is contained in by default. Code below FYI.
// ServiceComparisonPage
<?php
class ServiceComparisonPage extends Page {
public static $db = array(
);
public static $has_one = array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Services", new DataObjectManager(
$this,
'Services',
'Service',
null,
'getCMSFields_forPopup'
));
return $fields;
}
}
class ServiceComparisonPage_Controller extends Page_Controller {
public static $allowed_actions = array (
);
public function init() {
parent::init();
}
public function Services()
{
return DataObject::get('Service');
}
public function FeatureGroups() {
return DataObject::get('FeatureGroup');
}
}
// This is the Service Object
class Service extends DataObject {
static $db = array(
'Title' => 'Text'
);
static $many_many = array(
'Features' => 'Feature',
);
static $has_one = array(
'LinkTo' => 'SiteTree'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Title'),
new SimpleTreeDropdownField(
'LinkToID',
'Please select the page that this service links to...'
)
);
}
}