I can't figure out how to display the "Resources Link" under there appropriate "Resource Link Category" any help?
Here's the code.
ResourceLinkCategory.php
class ResourceLinkCategory extends DataObject {
static $db = array('Name' => 'Text');
static $has_many = array('ResourceLinks' => 'ResourceLink');
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push (new TextField('Name'));
return $fields;
}
}
ResourceLink.php
class ResourceLink extends DataObject {
static $db = array(
'URL' => 'Text',
'Description' => 'Text'
);
static $has_one = array(
'ResourceLinkPage' => 'ResourceLinkPage',
'MyResourceLinkCategory' => 'ResourceLinkCategory'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push (new TextField('URL'));
$fields->push (new TextareaField('Description'));
$fields->push (new HasOneDataObjectManager(
$this,
'MyResourceLinkCategory',
'ResourceLinkCategory',
array('Name' => 'Name'),
'getCMSFields'
));
return $fields;
}
}
ResourceLinkPage.php
class ResourceLinkPage extends Page {
static $has_many = array(
'ResourceLinks' => 'ResourceLink',
'ResourceLinkCategories' => 'ResourceLinkCategory'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$resourcelinks = new DataObjectManager(
$this,
'ResourceLinks',
'ResourceLink',
array(
'URL' => 'URL',
'Description' => 'Description'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.ResourceLinks', $resourcelinks);
return $fields;
}
}
class ResourceLinkPage_Controller extends Page_Controller {
function GetResourceLinkCategories() {
return DataObject::get('ResourceLinkCategory', '', '', '', '');
}
}
ResourceLinkPage.ss
<% control GetResourceLinkCategories %>
<h2><span>$Name</span></h2>
<-- Display Resources Link related to the Category here -->
<% end_control %>