5093 Posts in 1516 Topics by 1113 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1741 Views |
-
Can't Add Nested/Multiple Custom Tabs in CMS

2 February 2010 at 2:19am Last edited: 2 February 2010 2:20am
Hi All
I'd like to add a new set of tabs for my Page class, basically a Custom tab at the Content/Behaviour/To-Do level, and then another set of tabs underneath that tab. Unfortunately when I try to do so I get an error.
Let me be more specific -> when I add just a top level tab (that is addFieldToTab('Root.Custom',field) ) it works great, and if I try to add a sub tab to an already existing top level tab (eg addFieldToTab('Root.Content.Custom',field) ) it works fine too, but if I try to add a sub tab to the new top level tab (eg addFieldToTab('Root.Custom.Custom') ) this is when I get errors.
Below is a basic sample that I've used in Page.php and should replicate the error. If you remove the 'offending line' below, it should work. Leave it in and you'll get
FieldSet::addFieldToTab() Tried to add a tab to object 'Tab' named 'Custom' - 'CustomSub' didn't exist.
Line 272 in /path/to/silverstripe../sapphire/forms/FieldSet.phpHere's the snippet:
static $db = array(
'Test1' => 'Text',
'Test2' => 'Text',
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Custom', new TextField('Test1'));
$fields->addFieldToTab('Root.Custom.CustomSub', new TextField('Test2')); // The offending row
return $fields;
}I am using a very recent checkout of the 2.4 branch if that matters, but I'd have expected this to be pretty core functionality.
Also, I've come across this in my hunting http://silverstripe.org/customising-the-cms/show/252514#post252514 which I'm a bit afraid of - it seems to be the same issue, but is from over 12 months ago. Reeally hoping there's been a fix for this since?
Would really appreciate your help forum peeps!
-
Re: Can't Add Nested/Multiple Custom Tabs in CMS

2 February 2010 at 11:35am
I think a couple of things you could try - Try making sure Test1 is on its on subtab as well. Since I'm not too sure if SS likes having 1 field on the Root.Custom tab (only 1 level deep) then Root.Custom.Subtab. Try putting them both on Custom.Subtab.
Next thing you may need to do is manually create the tab before referencing it
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('Custom'));
$fields->addFieldToTab('Root.Custom', new TextField('Test1'));
... -
Re: Can't Add Nested/Multiple Custom Tabs in CMS

3 February 2010 at 3:43pm
Great! Thanks Willr, that pretty much did the trick.
When I used verbatim the sample you posted, the third line (when combined with the line before it) caused another error:
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('Custom'));
$fields->addFieldToTab('Root.Custom', new TextField('Test1'));I just mention that for people looking at this thread in future. The jist of it worked great, once I created the parent tab I could add as many custom tabs under it that I wanted. You were right I couldn't add a text field to the parent tab as well as having sub-tabs, but that was me not thinking through the code properly rather than actually wanting that outcome.
Working code:
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('Custom'));
$fields->addFieldToTab('Root.Custom.SubCustom', new TextField('test1'));
$fields->addFieldToTab('Root.Custom.OtherSubCustom', new TextField('test2'));
return $fields;
}Many thanks!
| 1741 Views | ||
|
Page:
1
|
Go to Top |


