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.

General Questions /

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

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

DataObjectDecorator Question


Reply


4 Posts   1250 Views

Avatar
DanStephenson

Community Member, 116 Posts

11 March 2011 at 12:40pm

Edited: 11/03/2011 1:12pm

Salutations,

I am trying to use the DataObjectDecorator to add some fields to the UserDefinedForm. I need to add a textbox for a Sidebar. When I use this code in my /code/ directory

<?php
class CustomForm extends DataObjectDecorator{
   function extraField(){
      return array(
         'db' => array(
            'Sidebar' => 'HTMLText'
         ),
         'has_one' => array(
         ),
      );
   }
   public function updateCMSFields(FieldSet $fields) {
      $fields->push(new HTMLEditorField('Sidebar','Sidebar'));
   }
}
?>

As well, I added the appropriate code onto the _config.php.

When I go into the CMS, the Sidebar field is anchored to the bottom of my editor window. It seems like the CMS is adding the field, but not into the Content->Main fieldset.

How can I add this field to a different tab, or change it's order so it's not anchored to the bottom?

Avatar
StuM

Community Member, 56 Posts

11 March 2011 at 3:19pm

perhaps try:

public function updateCMSFields(FieldSet $fields) {
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('Sidebar','Sidebar'));
}

Avatar
DanStephenson

Community Member, 116 Posts

12 March 2011 at 11:51am

Thanks Stu,

That worked - however I can't get the new field to save any data. When I add my data, and hit the "Save and Publish" button, the page refreshes and my field is blank. Any idea what's wrong?

Avatar
martimiz

Forum Moderator, 1132 Posts

15 March 2011 at 6:47am

Try using extraStatics() instead of extraFields():

function extraStatics() {
   return array(
      'db' => array(
         "Sidebar" => "HTMLText",
      )
   );
}

Then do a /dev/build/?flush=1...