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

Order field before fieldset in CMS admin


Go to End


4 Posts   5540 Views

Avatar
Derek

Community Member, 6 Posts

4 April 2011 at 6:59am

I want to place some fields in the Security tab under Members before the Search and Member List section. They get added the the Group table and then appear after the Member List section. Here is my code so far:

class GroupDecorator extends DataObjectDecorator
{
function extraStatics()
{
return array('db' => array(
'Email' => 'Varchar(255)',
'Website' => 'Varchar(255)'));
}
public function updateCMSFields(Fieldset & $fields)
{

$fields->addFieldToTab('Root.Members', new TextField('Email', 'Email'));
$fields->addFieldToTab('Root.Members', new TextField('Website', 'Website'));
return $fields;
}
}

Avatar
Willr

Forum Moderator, 5523 Posts

4 April 2011 at 9:21am

You can use the insertBefore() function rather than push to insert before a given field name (http://api.silverstripe.org/2.4/forms/fields-structural/FieldSet.html#methodinsertBefore) which is useful for inserting new tabs. For fields you can use the addFieldsToTab() with the optional 3 argument filled out with the field you want it to sit before (http://api.silverstripe.org/2.4/forms/fields-structural/FieldSet.html#methodaddFieldToTab)

Avatar
Derek

Community Member, 6 Posts

4 April 2011 at 11:44am

Thanks for your response.
I did see those parameters for addFieldsToTab() but in this case I don't see what field I'm putting it before. For the default layout of the Groups/Members page there is a search and then a members list. I want to put the new fields before this and after the Title (Group name)

Avatar
Derek

Community Member, 6 Posts

4 April 2011 at 1:09pm

I took a guess and this works:
$fields->addFieldToTab('Root.Members', new TextField('Email', 'Email'), 'Members');
$fields->addFieldToTab('Root.Members', new TextField('Website', 'Website'), 'Members');

My new fields of 'email' and 'website' now appear before the members search and list section.