So, I'm creating a site using SilverStripe, and I'm having some struggles trying to figure out the best way to accomplish a goal.
The site I'm creating has a HomePage where there are three "content boxes" that have a header, an image, and some links below them.
I am trying to allow my clients to manage the data that appears in each box.
I have a ContentBox DataObject class that has a few data members. I also have a HomePage class that has three instances of ContentBox, e.g.:
class HomePage extends Page {
static $has_one = array(
'LeftContentBox' => 'ContentBox',
'RightContentBox' => 'ContentBox',
'BottomContentBox' => 'ContentBox'
);
function getCMSFields() {
$fields = parent::getCMSFields();
// content boxes
$fields->addFieldsToTab('Root.Content.LeftContentBox', LeftContentBox::getCMSFieldsToInclude());
$fields->addFieldsToTab('Root.Content.RightContentBox', RightContentBox::getCMSFieldsToInclude());
$fields->addFieldsToTab('Root.Content.BottomContentBox', BottomContentBox::getCMSFieldsToInclude());
return $fields;
}
}
ContentBox has its own array() of fields:
class ContentBox extends DataObject {
...
function getCMSFieldsToInclude() {
$fields = array(
new TextField('HeaderText', 'Header Text'),
new TextField('HeaderLink', 'Header Link URL'),
new ImageField('Image')
);
return $fields;
}
}
When I try and edit a HomePage in the CMS, I get the following error:
FATAL ERROR: collateDataFields() I noticed that a field called 'HeaderText' appears twice in your form: 'Form_EditForm'. One is a 'TextField' and the other is a 'TextField'
At line 110 in /Applications/MAMP/htdocs/sapphire/forms/CompositeField.php
------
So, does anyone have any suggestions as to how I should design this? Do I need to make three separate subclasses of ContentBox (left, bottom, right) that implement different named fields?
Thanks in advance for any help you can provide.
-Andy