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.

Customising the CMS /

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

Adding new fields (after Content field)


Go to End


3 Posts   7912 Views

Avatar
ootersplace

Community Member, 16 Posts

3 March 2009 at 5:22am

I think I'm missing something obvious, but as per Tutorial 2, to add new fields to the CMS, you write:

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

return $fields;
}

This works, but all the fields are added before the "Content" field. Is there a way to re-order them so that the Content field shows up first in the CMS, and all the other fields underneath that one?

Thanks for any help!

Karl.

Avatar
Fuzz10

Community Member, 791 Posts

3 March 2009 at 10:51am

Welcome to Silverstripe !

That is because your new field will be added before content (last parameter)....

API-DOC
void addFieldToTab (string $tabName, FormField $field, [string $insertBefore = null])

* string $tabName: The name of the tab or tabset. Subtabs can be referred to as TabSet.Tab or TabSet.Tab.Subtab. This function will create any missing tabs.
* FormField $field: The FormField object to add to the end of that tab.
* string $insertBefore: The name of the field to insert before. Optional.

Avatar
ootersplace

Community Member, 16 Posts

3 March 2009 at 11:31am

Thank you -- I knew it was something that was staring me in the face! Removing 'Content' made everything better. :)

And thanks for the welcome!