2
votes

In SilverStripe's CMS I want to remove the Content tab within a page. I can do this as follows:

$fields->removeFieldsFromTab('Root.Content.Main', 'Content');

I then want to create my own custom tab:

$fields->addFieldToTab('Root.Content.MyTab', $myField);

However by adding my own custom tab it brings the Content tab back.

The other option is just to make MyTab the default 'up' tab. Is that possible?

2

2 Answers

9
votes

SilverStripe 2.4

To remove the Content tab in SilverStripe 2.4:

$fields->removeFieldFromTab('Root.Content', 'Main');

And to add a field to a tab named MyTab:

$fields->addFieldToTab('Root.Content.MyTab', $myField);

SilverStripe 3.1

To remove the Content tab in SilverStripe 3.1:

$fields->removeFieldFromTab('Root', 'Main');

And to add a field to a tab named MyTab:

$fields->addFieldToTab('Root.MyTab', $myField);

Notes

Removing the Content tab means you cannot control the page title.

removeFieldsFromTab removes a number of fields from a Tab/TabSet within this FieldList. It takes an array of field names as the second parameter.

removeFieldFromTab removes a single field from a Tab/TabSet within this FieldList. It takes a string field name as the second parameter.

In your case you want to use removeFieldFromTab not removeFieldsFromTab.

3
votes

I know this question is old but I had same problem and I've figured it out.

In getCMSFields() method I wrote

$fields = parent::getCMSFields();
$fields->removeByName('XXX'); //this line removes tab
return $fields;

where 'XXX' is name of my tab 'Root.XXX'

I hope it'll help someone.