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   365 Views

Avatar
Optic Blaze

Community Member, 165 Posts

21 April 2014 at 11:48pm

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

Community Member, 86 Posts

23 April 2014 at 3:09am

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

Community Member, 165 Posts

23 April 2014 at 5:38am

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