Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » DataObjectDecorator Question

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

Page: 1
Go to End
Author Topic: 1105 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    DataObjectDecorator Question Link to this post

    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?

  • StuM
    Avatar
    Community Member
    56 Posts

    Re: DataObjectDecorator Question Link to this post

    perhaps try:

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

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: DataObjectDecorator Question Link to this post

    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?

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: DataObjectDecorator Question Link to this post

    Try using extraStatics() instead of extraFields():

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

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

    1105 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.