Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Add Tab to AssetAdmin

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

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

Page: 1
Go to End
Author Topic: 981 Views
  • tv
    Avatar
    Community Member
    43 Posts

    Add Tab to AssetAdmin Link to this post

    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?

  • tv
    Avatar
    Community Member
    43 Posts

    Re: Add Tab to AssetAdmin Link to this post

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

  • elgordo
    Avatar
    Community Member
    69 Posts

    Re: Add Tab to AssetAdmin Link to this post

    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

  • elgordo
    Avatar
    Community Member
    69 Posts

    Re: Add Tab to AssetAdmin Link to this post

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

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