Jump to:

1030 Posts in 805 Topics by 311 members

Forum Module

SilverStripe Forums » Forum Module » Email notification for Forum registration

Discuss the Forum Module.

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

Page: 1
Go to End
Author Topic: 1655 Views
  • Juanitou
    Avatar
    Community Member
    323 Posts

    Email notification for Forum registration Link to this post

    Hi!

    I’ve been followed this thread (http://www.silverstripe.org/all-other-modules/show/277190) on comment notification. I’d like to implement something of this kind for new forum members; being informed of new registrations and validate them.

    As the example given by Will uses a DataObjectDecorator and the register() function is in a Page_Controller (ForumMemberProfile), I guess the decorator cannot extend it, so I should decorate ForumRole or Member (since the former decorated de latter) with some onAfterwrite.

    Could this work? (before I try by myself).

    Best regards,
    Juan

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Email notification for Forum registration Link to this post

    I think you can’t decorate a Decorator (now that I think of it, it seems quite obvious…).

    DataObject::add_extension('ForumRole', 'ForumMemberEmailNotification'); --> Breaks the site
    DataObject::add_extension('Member', 'ForumMemberEmailNotification'); --> Works

    I cannot call the parent function. Is it possible?

    /mysite/code/ForumMemberEmailNotification.php
    <?php

    class ForumMemberEmailNotification extends DataObjectDecorator {
       function onAfterWrite() {
          //$this->owner->onAfterWrite(); ////// I’ve tried a lot of things but they break the function
          
          $email = new Email();
          $email->setTemplate('NewMember');
          $email->setTo('xxx@xxx.xx');
          $email->setSubject('New Member');
          $email->sendPlain();
       }
    }
    ?>

    /mysite/config.php

    ...
    DataObject::add_extension('Member', 'ForumMemberEmailNotification');

    What can be wrong here? I have not forgotten to create the template. How can I debug Email()?

    Thanks in advance for any insight,
    Juan

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: Email notification for Forum registration Link to this post

    Juan, did you continue with this? Any progress or working code?

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Email notification for Forum registration Link to this post

    Hi!

    I’ve been too busy. I modified the ForumMemberProfile function doregister() directly, but know I found here the correct syntax. I need to take a course on PHP.

    So:

    /mysite/code/ForumMemberEmailNotification.php
    <?php

    class ForumMemberEmailNotification extends DataObjectDecorator {
    function onAfterWrite() {
    $email = new Email();
    $email->setTemplate('NewMember');
    $email->setTo('xxx@xxx.xx');
    $email->setSubject('New Member');
    $email->sendPlain();

    parent::onAfterWrite();
    }
    }
    ?>

    /mysite/config.php

    ...
    DataObject::add_extension('Member', 'ForumMemberEmailNotification');

    Hope it helps,
    Juan

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: Email notification for Forum registration Link to this post

    Thanks, Juan, for the input.

    Sooner or later I need that working. Currently other things are more urgent though. I still hope it'll get fixed by someone nice before it reaches the top of my "urgent" list ;)

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