21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 477 Views |
-
Add Tab to AssetAdmin

9 November 2012 at 12:23pm Last edited: 9 November 2012 12:24pm
I am trying to add a tab to AssetAdmin (as part of an attempt to upgrade Hamish Campbell's secure files module) and am having difficulty adding the Security tab in AssetAdmin.
I have looked over the code in AssetAdmin and found the code that appears to be responsible for the tabs in AssetsAdmin:
cms/code/controllers/AssetAdmin.php
if(!$fields->hasTabset()) {
$tabs = new TabSet('Root',
$tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')),
$tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))
);
....
}In the File decorator class in secure files I have changed the updateCMSFields method to be compatible with SS3:
function updateCMSFields(FieldList $fields) {
// Only modify folder objects with parent nodes
if(!($this->owner instanceof Folder) || !$this->owner->ID)
return;// Only allow ADMIN and SECURE_FILE_SETTINGS members to edit these options
if(!Permission::checkMember(Member::currentUser(), array('ADMIN', 'SECURE_FILE_SETTINGS')))
return;$secureFilesTab = $fields->findOrMakeTab('Root.'._t('SecureFiles.SECUREFILETABNAME', 'Security'));
...Unfortunately, this is giving me the following error:
Error at framework/forms/FieldList.php line 288: FieldList::addFieldToTab() Tried to add a tab to object 'FieldList' - 'Root' didn't existI have found the code in FieldList.php that is producing this error message:
if(is_a($parentPointer, 'TabSet')) {
// use $title on the innermost tab only
if ($k == $last_idx) {
$currentPointer = isset($title) ? new Tab($part, $title) : new Tab($part);
}
else {
$currentPointer = new TabSet($part);
}
$parentPointer->push($currentPointer);
}
else {
$withName = ($parentPointer->hasMethod('Name')) ? " named '{$parentPointer->getName()}'" : null;
user_error("FieldList::addFieldToTab() Tried to add a tab to object '{$parentPointer->class}'{$withName} - '$part' didn't exist.", E_USER_ERROR);
}I do not understand why 'Root' is not a TabSet, cinse it appears to be set as such in AssetAdmin.
Can anybody please help out on this one?
-
Re: Add Tab to AssetAdmin

12 November 2012 at 6:34am
If anybody else runs into this...
the getCMSFields method on Folder add fields to the DetailsView tab in AssetAdmin. So, rather than add a tab to Root (i.e., $fields->addFieldToTab('Root.Security), I added the Security fields to the FieldList:
public function updateCMSFields(FieldList $fields) {
// Only modify folder objects with parent nodes
if(!($this->owner instanceof Folder) || !$this->owner->ID)
return;
// Only allow ADMIN and SECURE_FILE_SETTINGS members to edit these options
if(!Permission::checkMember(Member::currentUser(), array('ADMIN', 'SECURE_FILE_SETTINGS')))
return;
$secureFilesFields= $fields;
$EnableSecurityHolder = new FieldGroup();
$EnableSecurityHolder->addExtraClass('securityFieldHolder');
if($this->InheritSecured()) {
$EnableSecurityField = new ReadonlyField('InheritSecurity', '', _t('SecureFiles.INHERITED', 'This folder is inheriting security settings from a parent folder.'));
$EnableSecurityField->addExtraClass('prependLock');
} else {
$EnableSecurityField = new CheckboxField('Secured', _t('SecureFiles.SECUREFOLDER', 'Folder is secure.'));
}
$secureFilesFields->push(new HeaderField(_t('SecureFiles.FOLDERSECURITY', 'Folder Security')));
$EnableSecurityHolder->push($EnableSecurityField);
$secureFilesFields->push($EnableSecurityHolder);
}The Security Boolean is now showing up in the DetailsView Tab.
Not sure if this is the most eloquent solution, but it is working for me...
-
Re: Add Tab to AssetAdmin

30 November 2012 at 5:45pm
I've just run into the same problem. Tabs are obviously possible as the form scaffolding creates them. Searching the code to try and figure out how
-
Re: Add Tab to AssetAdmin

30 November 2012 at 6:29pm
The following copied from FormScaffolder allows one to create tabs:
$fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
$mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));
| 477 Views | ||
|
Page:
1
|
Go to Top |

