Hi all :)
I've been trying for sometime to get DataObjects and CustomSiteConfig to work in 2.4. Is it even possible or am I wasting my time?
I have it working in the Admin where I can add dataobject items to the site config and it saves/works fine.
The problem is how do I call it from the Template? I've tried all sorts of variations as can be seen from my code below.
Am I missing something obvious?
Footer.ss
<% control FooterItems %>
<p>$SiteConfig.FooterText</p>
<% end_control %>
<% control SiteConfig.FooterItems %>
<p>$FooterText</p>
<% end_control %>
<% control MyFooters %>
<p>$SiteConfig.FooterText</p>
<% end_control %>
FooterItem.php
<?php
class FooterItem extends DataObject {
static $db = array(
'FooterText' => 'Text',
'FooterLink' => 'Text'
);
static $has_one = array(
//'FooterImage' => 'Page_Image',
'MyFooter' => 'CustomSiteConfig'
);
function MyFoom() {
return DataObject::get( 'CustomSiteConfig', "`MyFooterItemID` = '{$this->ID}'" );
}
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField('FooterText', 'Text' ) );
$fields->push( new TextField('FooterLink', 'Link' ) );
return $fields;
}
}
?>
CustomSiteConfig .php
<?php
class CustomSiteConfig extends DataObjectDecorator {
function extraStatics() {
return array(
'db' => array(
),
'has_one' => array(
),
'has_many' => array(
'MyFooter' => 'FooterItem',
),
);
}
public function updateCMSFields(FieldSet &$fields) {
$manager = new DataObjectManager(
$this->owner,
'MyFooter',
'FooterItem',
array(
'FooterText' => 'Text',
'FooterLink' => 'Link'
),
'getCMSFields_forPopup'
);
$manager->setSourceID($this->owner->ID);
$manager->setAddTitle( 'a new location' );
$fields->addFieldToTab('Root.Footer', $manager );
}
}