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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Add Tab to AssetAdmin


Go to End


4 Posts   4297 Views

Avatar
tv

Community Member, 44 Posts

9 November 2012 at 12:23pm

Edited: 09/11/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 exist

I 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?

Avatar
tv

Community Member, 44 Posts

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...

Avatar
elgordo

Community Member, 70 Posts

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

Avatar
elgordo

Community Member, 70 Posts

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"));