Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Decorating/Extending AssetAdmin - so that it shows a different folder

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

Page: 1
Go to End
Author Topic: 891 Views
  • robinp
    Avatar
    Community Member
    33 Posts

    Decorating/Extending AssetAdmin - so that it shows a different folder Link to this post

    Hi,

    In the CMS I need the AssetAdmin to show a custom folder. I might be going around this the wrong way. I'm try to decorate AssetAdmin.

    In my _config.php

    I've got

    Object::add_extension('AssetAdmin', 'MemberAssets');

    Then MemberAssets is

    <?php

    class MemberAssets extends DataObjectDecorator {
       
       function init() {
             echo 'init happening - maybe two lots of data decoratoring does not work';
       }
       

       /**
        * Return the entire site tree as a nested UL.
        * @return string HTML for site tree
        */
       public function SiteTreeAsUL() {

          $obj = singleton('Folder');
          $obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder'));
          $obj->markPartialTree(30, null, "ChildFolders");

          if($p = $this->currentPage()) $obj->markToExpose($p);

          // getChildrenAsUL is a flexible and complex way of traversing the tree
          $siteTreeList = $obj->getChildrenAsUL(
             '',
             '"<li id=\"record-$child->ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
             '"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" class=\"" . ($child->hasChildFolders() ? " contents" : "") . "\" >" . $child->TreeTitle() . "</a>" ',
             $this,
             true,
             "ChildFolders"
          );   

          // Wrap the root if needs be
          $rootLink = $this->Link() . 'show/root';
          $baseUrl = Director::absoluteBaseURL() . "assets/";
          if(!isset($rootID)) {
             $siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\"><li id=\"record-root\" class=\"Root\"><a href=\"$rootLink\"><strong>EXTENDED{$baseUrl}</strong></a>"
             . $siteTreeList . "</li></ul>";
          }

          return $siteTree;
       }
       
       

    }

    I've got init happening - maybe two lots of data decoratoring does not work showing.

    Does any have ideas about what I've doing wrong? or there another solution to my problem ?

    Cheers

    Robin

  • Sphere
    Avatar
    Community Member
    44 Posts

    Re: Decorating/Extending AssetAdmin - so that it shows a different folder Link to this post

    I've been trying the same. But yeah, the SiteTreeAsUl extend doesn't work. Have you found a solution yet?

    I think it's easier to just set the rootfolder, but haven't really found out yet how to.

  • robinp
    Avatar
    Community Member
    33 Posts

    Re: Decorating/Extending AssetAdmin - so that it shows a different folder Link to this post

    Hi,

    Yes I did solve it.

    What I've got is

    class MemberAssets that extends AssetsAdmin

    Then I've got some like

    public function SiteTreeAsUL() {
          
          
           if(Permission::checkMember(Member::currentUser(), "ADMIN")) {
              return $this->AdminSiteTreeAsUL();
             
           } else {
              return $this->UserSiteTreeAsUL();
           }

       
       }

    Then tidy up the CMS menu in the _config.php I've got

    Director::addRules(100,array('admin/files/$Action/$ID/$OtherID' => 'MemberAssets'));

    CMSMenu::remove_menu_item('AssetAdmin');
    CMSMenu::remove_menu_item('MemberAssets');//this seems to be a bit hack but it works
    CMSMenu::add_link('AssetAdmin', 'Files', 'admin/files', $priority = 2);

    I hope that helps

    Cheers

    Robin

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