From 1685ee2070ceaf94bea49031e0a946aef5feb567 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 22 Apr 2013 13:47:22 +1200 Subject: [PATCH] UPDATED: 3.1 compatibility ADDED: Extension hook for updating email object prior to send UPDATED: Documentation --- README.md | 15 +++++++++++++++ code/CommentsNotifications.php | 2 +- ...CommentingControllerNotificationsExtension.php | 4 +++- .../extensions/CommentsNotificationsExtension.php | 4 ++-- .../PageCommentsNotificationsExtension.php | 2 +- .../SiteConfigCommentsNotificationsExtension.php | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf65050..b164c00 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,21 @@ CommentsNotifications: recipient: 'Page' ``` +## Extending + +To hook into the outgoing email (in order to customise the template) you can +extend CommentingController with an extending class with a function updateEmail + +```php +class EmailSenderExtension extends Extension { + public function updateEmail(Email &$email) { + $email->populateTemplate(array( + 'SiteConfig' => SiteConfig::current_site_config() + )); + } +} +``` + ## Need more help? Message or email me at damian.mooyman@gmail.com or, well, read the code! diff --git a/code/CommentsNotifications.php b/code/CommentsNotifications.php index fb92c2a..6e5d4dd 100644 --- a/code/CommentsNotifications.php +++ b/code/CommentsNotifications.php @@ -31,4 +31,4 @@ public static function get_recipient($parent) { default: return $recipient; } } -} \ No newline at end of file +} diff --git a/code/extensions/CommentingControllerNotificationsExtension.php b/code/extensions/CommentingControllerNotificationsExtension.php index ffb33a2..d7d4d47 100644 --- a/code/extensions/CommentingControllerNotificationsExtension.php +++ b/code/extensions/CommentingControllerNotificationsExtension.php @@ -38,7 +38,9 @@ public function onAfterPostComment(Comment $comment) { $email->addCustomHeader('X-Sender', $sender); $email->addCustomHeader('Sender', $sender); + $this->owner->extend('updateEmail', $email); + // Send $email->send(); } -} \ No newline at end of file +} diff --git a/code/extensions/CommentsNotificationsExtension.php b/code/extensions/CommentsNotificationsExtension.php index 75e0c67..146017f 100644 --- a/code/extensions/CommentsNotificationsExtension.php +++ b/code/extensions/CommentsNotificationsExtension.php @@ -4,7 +4,7 @@ * @author Damian Mooyman */ class CommentsNotificationsExtension extends DataExtension { - static $db = array( + private static $db = array( 'CommentNotificationEmail' => 'Varchar(255)' ); -} \ No newline at end of file +} diff --git a/code/extensions/PageCommentsNotificationsExtension.php b/code/extensions/PageCommentsNotificationsExtension.php index d07356c..9086c4f 100644 --- a/code/extensions/PageCommentsNotificationsExtension.php +++ b/code/extensions/PageCommentsNotificationsExtension.php @@ -13,4 +13,4 @@ public function updateSettingsFields(FieldList $fields) { ); } } -} \ No newline at end of file +} diff --git a/code/extensions/SiteConfigCommentsNotificationsExtension.php b/code/extensions/SiteConfigCommentsNotificationsExtension.php index 4930bfa..381a36e 100644 --- a/code/extensions/SiteConfigCommentsNotificationsExtension.php +++ b/code/extensions/SiteConfigCommentsNotificationsExtension.php @@ -13,4 +13,4 @@ public function updateCMSFields(FieldList $fields) { ); } } -} \ No newline at end of file +}