Hello,
I'm trying to achieve the following in the administration panel. I'd like to add a tab to the default Page class, for example widgets or in my case a custom tab to add data to the page. Now adding the tab is not a problem, in the getCMSFields() function I do the following:
$newsGridField = new GridField('NewsItems', _t('NewsPage.NewsItems', 'News items'), $this->NewsItems(), $config);
$fields->addFieldToTab('Root.NewsItems', $newsGridField);
The problem is that the tab name is now NewsItems, which is also the title. I check the SiteTree file, which also defines the tab structure but keeps the component's variables and then uses $TABNAME->setTitle() function to set a title. Now I did something similar however this is not flexible at all:
$fields->items[0]->children->items[2]->setTitle(_t('NewsPage.NewsItems', 'News items'));
Isn't there a dynamic/simple way to access a tab and change it's properties, like it's title? The above example will only work in the case that the tab is a third tab, but if it is the second or fourth it will fail to name the correct tab.
Preferably i'd like something like this: (PSeudocode)
function getCMSFields() {
$fields = parent::getCMSFields();
$newField = new SomeField('idString', _t('text.ID', 'ID text');
$fields->addFieldToTab('Root.NewTab', $newField);
$fields->setTabTitle('Root.NewTab', _t('text.TabName', 'Some name');
return $fields;
}
Or something like:
function getCMSFields() {
$fields = parent::getCMSFields();
$tab = new Tab('NewTab',
$newField = new SomeField('idString', _t('text.ID', 'ID text');
$fields->addTab('Root', $tab);
return $fields;
}