Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Adding tabs to the admin interface which are translatable.


Reply


3 Posts   839 Views

Avatar
DubbeleJ

Community Member, 9 Posts

9 September 2012 at 10:22am

Edited: 09/09/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;
}

Avatar
jak

Community Member, 46 Posts

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;
}

Avatar
DubbeleJ

Community Member, 9 Posts

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.