In SilverStripe 4, how to extend an existing method when there is no Extension Hook inside the original method?

人盡茶涼 提交于 2019-12-11 00:55:47

问题


I want to override 'loginForm' method in 'LoginHandler' class. I am trying to use the code given below for that. But it is not working.

LoginHandlerExtension.php

    <?php

    use SilverStripe\Core\Extension;

    class LoginHandlerExtension extends Extension {

        public function loginForm() {
            return 'xxxxxx';
        }
    }

app.yml

SilverStripe\Security\MemberAuthenticator\LoginHandler:
  extensions:
    - LoginHandlerExtension

回答1:


What would you want to override on the loginForm method? If you want it to use a different Form class (e.g. MyMemberLoginForm), you can tell Injector to use your custom class in YML like this:

SilverStripe\Core\Injector\Injector:
  MemberLoginForm:
    class: My\Namespaced\LoginForm

as the LoginForm method does nothing else but return the form.



来源:https://stackoverflow.com/questions/49247389/in-silverstripe-4-how-to-extend-an-existing-method-when-there-is-no-extension-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!