3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 310 Views |
-
Adding tabs to the admin interface which are translatable.

9 September 2012 at 10:22am Last edited: 9 September 2012 10:25am
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;
} -
Re: Adding tabs to the admin interface which are translatable.

18 September 2012 at 7:36am
It should work like this:
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new Tab('MyTab', _t('MyTab.MyTabTitle', 'This is my tab')));
$fields->addFieldToTab('Root.MyTab', $myField);
return $fields;
} -
Re: Adding tabs to the admin interface which are translatable.

19 September 2012 at 8:41am
Thanks for your answer, that is what I was looking for.
Never thought of the fact to add a field like that to the root.Regards.
| 310 Views | ||
|
Page:
1
|
Go to Top |

