I was wondering if it is possible to add a Tab via a DataExtension? The FieldList argument passed to updateCMSFields appears to output a DataExtensions new fields onto the Details Tab. So my first attempt was to push my Fields there:
public function updateCMSFields(FieldList $fields) {
$secureFilesTab = $fields;
$secureFilesTab->push(new HeaderField(_t('SecureFiles.GROUPACCESSTITLE', 'Group Access')));
$secureFilesTab->push(new TreeMultiselectField('GroupPermissions', _t('SecureFiles.GROUPACCESSFIELD', 'Group Access Permissions')));
}
This works fine, but when I save a value, the CMS loads the data from the Tree_View and List_View tabs onto the Details Tab. Mentioned in comments below is the fact that this is a DataExtension for Folder.
I then tried using code from the FormScaffolder to add a new Tab:
public function UpdateCMSFields(FieldList $fields) {
$fields->push(new TabSet('Root', $secureFilesTab = new Tab('Security')));
$secureFilesTab->setTitle(_t('SiteTree.TABSECURITY', 'Security'));
}
This changes the tab icons all to the Tree_View icons and places my new DataExtension fields on all tabs.
What is the proper way to add tabs via a DataExtension?
You can use addFieldsToTab() to add new fields to an existing tab or a new one, as you would when using getCMSFields() on DataObjects.
The Security tab, if not found, will be created by passing ‘Root.Security’ as the first argument. The dot notation is used to create the nested structure of tabset and tabs. It is not possible to simple push a new tabset with the same name (“Root”), as there’s already such a tabset. If you need to do further manipulations on your tabs, you can access their instance using $fields->findOrMakeTab(‘TabSet.Tab’), ie $fields->findOrMakeTab(‘Root.Content’);