Alan A
Alan A

Reputation: 2551

SilverStripe Tab Customization

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?

Upvotes: 2

Views: 2848

Answers (3)

John Broadwater
John Broadwater

Reputation: 1

For Silverstripe 5.x:

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

Upvotes: 0

3dgoo
3dgoo

Reputation: 15794

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.

Upvotes: 9

Robert
Robert

Reputation: 20286

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.

Upvotes: 3

Related Questions