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.

Form Questions

[Solved] Reorder fields when using updateCMSFields


Reply

3 Posts   282 Views

Avatar
Optic Blaze

21 April 2014 at 11:48pm Community Member, 162 Posts

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
Avatar
thomas.paulson

23 April 2014 at 3:09am Community Member, 79 Posts

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');
}

Avatar
Optic Blaze

23 April 2014 at 5:38am Community Member, 162 Posts

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()
      ));
   
   }