Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Adding tabs to the admin interface which are translatable.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 700 Views
  • DubbeleJ
    Avatar
    Community Member
    9 Posts

    Adding tabs to the admin interface which are translatable. Link to this post

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

  • jak
    Avatar
    Community Member
    46 Posts

    Re: Adding tabs to the admin interface which are translatable. Link to this post

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

  • DubbeleJ
    Avatar
    Community Member
    9 Posts

    Re: Adding tabs to the admin interface which are translatable. Link to this post

    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.

    700 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.