Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » [Solved] Reorder fields when using updateCMSFields

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

Page: 1
Go to End
Author Topic: 257 Views
  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    [Solved] Reorder fields when using updateCMSFields Link to this post

    Hi there,

    I have extended Page/Sitetree. Everything works, but i cant seem to reorganize the fields the way i want to. This is not the normal getCMSFields function that i am using but rather the updateCMSFields function. What i want to do is have the 'Multicolumn' field appear above the Content or Title Section (see screenshot)

    public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab('Root.Main', new DropDownField("MultiColumn","Build Multiple Columns?",array("1"=>"Yes","0"=>"No"),"Title"));
       }

    Attached Files
  • thomas.paulson
    Avatar
    Community Member
    75 Posts

    Re: [Solved] Reorder fields when using updateCMSFields Link to this post

    You can use third param of addFieldToTab ie insertBefore feild

    public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab('Root.Main', new DropDownField("MultiColumn","Build Multiple Columns?",array("1"=>"Yes","0"=>"No"),"Title"), 'Content');
    }

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: [Solved] Reorder fields when using updateCMSFields Link to this post

    Hi, i tried that but it did not work. From the docs it looks like the update CMS function fetches the parent results and only then modifies the CMS with the new fields.

    The following did however work:

    public function updateCMSFields(FieldList $fields) {
          // Remove old content field
          $fields->removeByName("Content");
          
          // Add fields
           $fields->addFieldsToTab("Root.Main", array(
          DropDownField::Create("MultiColumn","Build Multiple Columns?",array("1"=>"Yes","0"=>"No")),
          HtmlEditorField::Create("Content","Content")->displayIf("MultiColumn")->isEqualTo("0")->end()
          ));
       
       }

    257 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.