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.

Customising the CMS

Extending core classes (like Security)


Go to End
Reply

9 Posts   3427 Views

Avatar
Mad_Clog

31 March 2009 at 2:56am Community Member, 78 Posts

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

Avatar
Mad_Clog

31 March 2009 at 6:47pm Community Member, 78 Posts

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

Avatar
Ben Gribaudo

1 April 2009 at 2:32am Community Member, 181 Posts

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

Avatar
Mad_Clog

1 April 2009 at 3:35am (Last edited: 1 April 2009 3:36am), Community Member, 78 Posts

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

Avatar
Mad_Clog

3 April 2009 at 9:17am Community Member, 78 Posts

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

Avatar
Crion

3 April 2009 at 9:16pm Community Member, 1 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.

Avatar
Mad_Clog

6 April 2009 at 7:24pm Community Member, 78 Posts

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.

Avatar
klikhier

14 February 2012 at 11:32pm (Last edited: 14 February 2012 11:35pm), Community Member, 150 Posts

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

Go to Top