Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Inheriting CMSMain

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

Page: 1
Go to End
Author Topic: 1338 Views
  • rainerh
    Avatar
    Community Member
    23 Posts

    Inheriting CMSMain Link to this post

    Hello,

    I want to add some further plugins to TinyMCE and some methods to CMSMain. For this reason I've created a class that inherits directly from CMSMain and overwrites some methods.
    Unfortunately when the user enters the url /admin the CMSMain object is still called. I've added following command to _config.php so that SilverStripe is calling the MyMain object:

    Director::addRules(60, array(
       'admin/cms//$Action/$ID/$OtherID' => 'MyMain',
    ));

    That does not work. Am I missing something???

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Inheriting CMSMain Link to this post

    Hm strange indeed. I never tried that.
    Did you do a dev/build? Otherwise SilverStripe probably won't find the appropriate class (MyMain)

  • rainerh
    Avatar
    Community Member
    23 Posts

    Re: Inheriting CMSMain Link to this post

    Hi there,

    /dev/build doesn't help. MyMain is recognized since a rule like '/testmain' works perfectly.

    Greetings!

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Inheriting CMSMain Link to this post

    I am currently in the middle of doing this, and quite frankly its a pain in the ass!

    So far I have added this to my dashboard modules _config.php file:

    Director::addRules(50, array(
       'admin/dashboard'   => 'DashboardAdmin'
    ));

    CMSMain::$url_segment = 'cms';

    CMSMenu::replace_menu_item('CMSMain', 'Site Content', 'admin/cms/', null, 10);

    And added this class to extend the CMS' main menu:

    class DashboardAdmin extends LeftAndMain {
       static $url_segment = '';
       
       static $menu_title = 'Dashboard';
       
       static $menu_priority = 99;
       
       static $url_priority = 41;

       /**
        * Initialisation method called before accessing any functionality that RandomLinksAdmin has to offer
        */
       public function init() {
          parent::init();
          
          Requirements::css('dashboard/css/Dashboard.css');
          Requirements::customScript(file_get_contents(Director::baseFolder() . '/dashboard/javascript/Dashboard.js'));
       }
       
       ...

    }

    ?>

    The most important lines are:

    static $url_segment = '';
    static $url_priority = 41;

    These basically tell Silverstripe that your new class has a higher priority than CMSMain. Please note though that url_priority can't exceed 49!

    Doing this overrides the default behaviour of the CMS, but for me has caused a load of new isses, so I am now trying to extend CMSMain to fix them, I will post back when I get a result

    Mo

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Inheriting CMSMain Link to this post

    Not sure if you have read this, but it has some handy snippets: http://doc.silverstripe.com/doku.php?id=cmsmain

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