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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

[Solved] Reorder fields when using updateCMSFields


Go to End


3 Posts   2190 Views

Avatar
Optic Blaze

Community Member, 190 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, 107 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, 190 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()
));

}