Please upgrade here. These earlier versions are no longer being updated and have security issues.

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?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

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

  • hgtonighthgtonight ∞ · New Moderator

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

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

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

    example?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • hgtonighthgtonight ∞ · New Moderator

    @peregrine said:
    example?

    Incoming...

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    R_J
  • hgtonighthgtonight ∞ · New Moderator

    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.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

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

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

    grep is your friend.

    BleistivtperegrineR_JClément
  • 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.

    hgtonight
Sign In or Register to comment.