Override method Gdn_Email->Send();

I would like to override the method: Gdn_Email->Send();

I can not with (in a extension): public function Gdn_Email_Send_Override(&$Sender) {}

Yet I have read the documentation.

Do you have any idea?

Best Answer

Answers

  • peregrineperegrine MVP
    edited October 2014

    latest info on magic events.

    http://docs.vanillaforums.com/developers/plugins/

    maybe you can get by using FireEvent -

    https://github.com/vanilla/vanilla/blob/2.1/library/core/class.email.php#L247

    what is it that you actually want to change?

  • Thank you for your reply.

    I tried using the SendMail event but it does not work because the variable $EventName is empty (tested when creating a new account). :\

    My goal is to be able to send emails site + forum with the same function. (html, header + footer).

    I will look to replace the whole class.

  • Extend the class, rewrite the method, and register your custom class as an alias in the autoloader.

  • register your custom class as an alias in the autoloader.

    example?

  • @peregrine said:
    example?

    Incoming...

  • So... I mixed up.

    You can alias classes that are accessed via the Gdn class such as Gdn::Session() using the following code:

    $OriginalFactoryOverwrite = Gdn::FactoryOverwrite(1);
    Gdn::FactoryInstall(Gdn::AliasSession, 'MyCustomSession');
    Gdn::FactoryOverwrite($OriginalFactoryOverwrite);
    

    You can also override classes by placing them in the appropriate folder of your plugin. Alternatively, you can register a different mapping to the autoloader:

    $Map     = Gdn_Autoloader::MAP_LIBRARY;
    $Context = Gdn_Autoloader::CONTEXT_PLUGIN;
    $Path    = PATH_PLUGINS . DS . 'CustomEmailClass' . DS . 'someBetterFolderName';
    $Options = array();
    
    Gdn_Autoloader::RegisterMap($Map, $Context, $Path, $Options);
    

    You cannot, however extend a class and then override that same class, unless it is accessed through the Gdn class. This is because the act of extending the class brings it into scope.

    Sorry for the error on my part.

  • All you have to do is predefine the class then it will skip the autoloader

    http://vanillaforums.org/discussion/comment/206846/#Comment_206846

  • Thank you very much for your answers !!

    I confirm @hgtonight: if the class is placed in the library folder plugin, it is automatically loaded.

    Too bad we can not just override some methods as with Prestashop.

Sign In or Register to comment.