Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Extending core classes (like Security)

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

Page: 1 2
Go to End
Author Topic: 3271 Views
  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Extending core classes (like Security) Link to this post

    Hi,

    I was wondering how I could extend core classes within SilverStripe.
    For example I want to extend Security and overrule setDefaultAdmin() and check_default_admin() to allow a hashed password to be used instead of plain-text.
    I could of course alter Security.php itself, but I don't want to lose my changes when updating to a newer version.

    Any help would be much appreciated!

    Cheers,
    Geert

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: Extending core classes (like Security) Link to this post

    The only solution I came up with so far is to copy Security.php to mysite/code/Security.php and make sure that get's loaded instead of the original one.
    This is still gonna be a hassle upgrading though, but at least changes won't be overwritten this way.

    To further expand my question, how expendable / customizable is SilverStripe.
    - What can be changed besides modules and templates?
    - What are no goes?
    - etc etc

    Cheers

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Extending core classes (like Security) Link to this post

    Hi Geert,

    Have you tried Object::useCustomClass('OldClass','NewClass')? Not sure if it will work for replacing Security as it only works for some classes. More details: http://silverstripe.org/template-questions/show/255567
    Ben

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: Extending core classes (like Security) Link to this post

    Hi Ben,

    The problem there is that some functions are called statically (in particular the ones I want to overrule), so the class name should be the same.
    Something like Object::useCustomClass('Security','Security'); is bound to fail.
    So i think the problem still remains...
    Thanks for your reply though.

    Also my other question about the limits of customization still remains.

    Geert

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: Extending core classes (like Security) Link to this post

    Sorry to bring this up again, but still looking for answers.
    Thanks in advance

  • Crion
    Avatar
    Community Member
    1 Post

    Re: Extending core classes (like Security) Link to this post

    Just an idea: Read a little about SVN and use the SS repository to get the source code and modify it like you want. To get a new version, just update the repository, and it merges edited files automatically.

  • Mad_Clog
    Avatar
    Community Member
    78 Posts

    Re: Extending core classes (like Security) Link to this post

    The SVN option was already considered, but the preferred option would be to alter the CMS without actually modifying the source code.
    With DataObject this can indeed be done perfectly, but as stated before this doesn't work that well on other classes.

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Extending core classes (like Security) Link to this post

    Although this is post is quite old, I'm having the same problem here. See below for the changes that I've hacked into Security.php (mostly it's commenting out the functionality for the tabs). Problem now is that I have to create CustomLoginForm.ss for all my other websites too, and that's not the idea here.

    O, and my actual requirement: how can I load Security_login in a 100% custom template WITHOUT all kinds of JS and CSS stuff being put in (which is currently done by Security.php).

    PS. I have tried <% control LoginForm %> in Security_login, but than the error messages ("wrong email/pass") are not shown

    //      // only display tabs when more than one authenticator is provided
    //      // to save bandwidth and reduce the amount of custom styling needed
    //      if(count($forms) > 1) {
    //         Requirements::javascript(SAPPHIRE_DIR . '/javascript/loader.js');
    //         Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
    //         Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
    //         Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
    //         Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/effects.js");
    //         Requirements::css(SAPPHIRE_DIR . "/css/Form.css");
    //         
    //         // Needed because the <base href=".."> in the template makes problems
    //         // with the tabstrip library otherwise
    //         $link_base = Director::absoluteURL($this->Link("login"));
    //         
    //         Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
    //         Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js");
    //         Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js");
    //         Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css");
    //         
    //         $content = '<div id="Form_EditForm">';
    //         $content .= '<ul class="tabstrip">';
    //         $content_forms = '';
    //
    //         foreach($forms as $form) {
    //            $content .= "<li><a href=\"$link_base#{$form->FormName()}_tab\">{$form->getAuthenticator()->get_name()}</a></li>\n";
    //            $content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">' . $form->forTemplate() . "</div>\n";
    //         }
    //
    //         $content .= "</ul>\n" . $content_forms . "\n</div>\n";
    //      } else {
    //         $content .= $forms[0]->forTemplate();
    //      }
       
          $content .= $forms[0]->renderWith('CustomLoginForm');

    3271 Views
Page: 1 2
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.