Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Data object trouble


Go to End


5 Posts   1214 Views

Avatar
Harley

Community Member, 165 Posts

14 September 2009 at 12:47pm

Hi,

Having a small problem here with a data object, just can't see the problem, maybe someone can spot it.

Basically I have a data object that I am trying to use in my homepage, but when I click on my tab I am getting no form field as you will see in the attached image.

This is the code in my homepage:

class elevatorHomePage extends Page {

static $db = array();

static $has_one = array(
'myAboutPage' => 'AboutPage'
);

static $icon = "themes/elevator/images/treeicons/home";

static $allowed_children = array('AboutPage', 'VacanciesPage');

function getCMSFields() {
$fields = parent::getCMSFields();

$tableField = new ComplexTableField(
$this,
'myAboutPage',
'AboutPage',
array(
'AboutContent' => 'About'
),
'getCustomCMSFields'
);

$tableField->setParentClass('elevatorHomePage');

$fields->addFieldToTab('Root.Content.About', new HtmlEditorField('About'), $tableField);
return $fields;
}

}

and this is the corresponding data object:

class AboutPage extends DataObject {
static $db = array(
'AboutContent' => 'Text',
);

static $has_one = array(
'elevatorHomePages' => 'elevatorHomePage'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.About', new HtmlEditorField('About'), 'AboutContent');
return $fields;
}

}

Attached Files
Avatar
bummzack

Community Member, 904 Posts

14 September 2009 at 6:52pm

When you setup your ComplexTableField, you're supplying the constructor with the name of the method to get the DataObject Form-Fields (for editing in the CMS). In your case, you set this to: getCustomCMSFields, therefore you should rename the method of your DataObject from getCMSFields to getCustomCMSFields.

Avatar
Harley

Community Member, 165 Posts

15 September 2009 at 12:32pm

Thanks for the info, I've changed the name of the method so everything now corresponds, I've reverted it back to getCMSFields.

No joy though, what else could be wrong with the script?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 September 2009 at 9:09am

You're trying to add two fields at once.

$fields->addFieldToTab('Root.Content.About', new HtmlEditorField('About'), $tableField);

either use addFieldsToTab("tab",array(field1,field2))'

or

addFieldToTab("tab",field1);
addFieldToTab("tab",field2);

Avatar
Harley

Community Member, 165 Posts

16 September 2009 at 12:45pm

Ok, I've tried that too and just to show where I am up to here with the code here we are;

About;

class AboutPage extends DataObject {
static $db = array(
'AboutContent' => 'Text',
);

static $has_one = array(
'elevatorHomePages' => 'elevatorHomePage'
);

function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('About'), 'Content');
return $fields;
}
}

Home;

class elevatorHomePage extends Page {

static $db = array();

static $has_one = array(
'myAboutPage' => 'AboutPage'
);

static $icon = "themes/elevator/images/treeicons/home";

static $allowed_children = array('AboutPage');

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.About', new HtmlEditorField('About'));
return $fields;
}

}

Still no joy though, I get a HtmlEditorField, but when I enter content here and save it, then go back to it, it reverts back to a blank field.

It looks correct to me, is there anything glaringly obvious I have missed here?

Thanks