diff --git a/src/Extensions/CommentNotifiable.php b/src/Extensions/CommentNotifiable.php index bca4c1e1..4a9b8097 100644 --- a/src/Extensions/CommentNotifiable.php +++ b/src/Extensions/CommentNotifiable.php @@ -40,14 +40,13 @@ class CommentNotifiable extends DataExtension */ public function notificationRecipients($comment) { - // Override this in your extending class to declare recipients - $list = array(); + $list = []; if ($adminEmail = Email::config()->admin_email) { $list[] = $adminEmail; } - $this->owner->extend('updateNotificationRecipients', $list, $comment); + $this->owner->invokeWithExtensions('updateNotificationRecipients', $list, $comment); return $list; } @@ -62,7 +61,9 @@ public function notificationRecipients($comment) public function notificationSubject($comment, $recipient) { $subject = $this->owner->config()->default_notification_subject; - $this->owner->extend('updateNotificationSubject', $subject, $comment, $recipient); + + $this->owner->invokeWithExtensions('updateNotificationSubject', $subject, $comment, $recipient); + return $subject; } @@ -83,7 +84,8 @@ public function notificationSender($comment, $recipient) : 'localhost'; $sender = preg_replace('/{host}/', $host, $sender); - $this->owner->extend('updateNotificationSender', $sender, $comment, $recipient); + $this->owner->invokeWithExtensions('updateNotificationSender', $sender, $comment, $recipient); + return $sender; } @@ -97,7 +99,9 @@ public function notificationSender($comment, $recipient) public function notificationTemplate($comment, $recipient) { $template = $this->owner->config()->default_notification_template; - $this->owner->extend('updateNotificationTemplate', $template, $comment, $recipient); + + $this->owner->invokeWithExtensions('updateNotificationTemplate', $template, $comment, $recipient); + return $template; } @@ -110,5 +114,6 @@ public function notificationTemplate($comment, $recipient) */ public function updateCommentNotification($email, $comment, $recipient) { + // } } diff --git a/src/Extensions/CommentNotifier.php b/src/Extensions/CommentNotifier.php index 6364eff7..712f41f9 100644 --- a/src/Extensions/CommentNotifier.php +++ b/src/Extensions/CommentNotifier.php @@ -86,12 +86,7 @@ public function notifyCommentRecipient($comment, $parent, $recipient) ]); } - // Until invokeWithExtensions supports multiple arguments - if ($this->owner->hasMethod('updateCommentNotification')) { - $this->owner->updateCommentNotification($email, $comment, $recipient); - } - - $this->owner->extend('updateCommentNotification', $email, $comment, $recipient); + $this->owner->invokeWithExtensions('updateCommentNotification', $email, $comment, $recipient); return $email->send(); } diff --git a/tests/CommentNotifiableTest.php b/tests/CommentNotifiableTest.php index 5a5fac43..c1114113 100644 --- a/tests/CommentNotifiableTest.php +++ b/tests/CommentNotifiableTest.php @@ -43,7 +43,7 @@ public function testGetRecipients() $item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); $item2 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item2'); - $this->assertEquals(array('andrew@address.com'), $item1->notificationRecipients($comment1)); + $this->assertEquals(array('myadmin@mysite.com', 'andrew@address.com'), $item1->notificationRecipients($comment1)); $this->assertEquals(array('myadmin@mysite.com'), $item2->notificationRecipients($comment2)); } diff --git a/tests/Model/CommentNotifiableTestDataObject.php b/tests/Model/CommentNotifiableTestDataObject.php index 3f06ef78..4cb5342e 100644 --- a/tests/Model/CommentNotifiableTestDataObject.php +++ b/tests/Model/CommentNotifiableTestDataObject.php @@ -27,15 +27,13 @@ class CommentNotifiableTestDataObject extends DataObject implements TestOnly private static $table_name = 'CommentNotifiableTestDataObject'; - public function notificationRecipients($comment) + public function updateNotificationRecipients(&$list, $comment) { $author = $this->Author(); if ($author && $author->exists()) { - return [$author->Email]; + $list[] = $author->Email; } - - return parent::notificationRecipients($comment); } public function Link($action = false)