silverstripe / comment-notifications
为访客评论提供电子邮件通知
3.0.0
2023-04-27 02:54 UTC
Requires
- php: ^8.1
- silverstripe/comments: ^4
- silverstripe/framework: ^5
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3
This package is auto-updated.
Last update: 2024-09-11 04:40:31 UTC
README
为当新访客评论发布时提供简单的电子邮件通知。
安装
composer require silverstripe/comment-notifications
配置
要将默认接收通知的电子邮件地址配置为,请在 mysite/_config.yml
中放置以下内容
SilverStripe\Control\Email\Email: admin_email: 'will@fullscreen.io'
查看 CommentNotifiable 类以获取您可以在项目中覆盖的选项列表。
配置接收者
要定义谁接收评论通知,请定义一个 updateNotificationRecipients
方法并修改电子邮件地址列表。
mysite/code/CommentNotificationExtension.php
<?php use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Comments\Model\Comment; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataExtension; use SilverStripe\Security\Group; class CommentNotificationExtension extends DataExtension { /** * @param array $existing * @param Comment $comment */ public function updateNotificationRecipients(&$existing, $comment) { // send notification of the comment to all administrators in the CMS $admin = Group::get()->filter('Code', 'admin'); foreach ($admin as $group) { foreach ($group->Members() as $member) { $existing[] = $member->Email; } } // or, notify the user who originally created the page $page = $comment->Parent(); if ($page instanceof SiteTree) { /** @var ArrayList $pageVersion */ $pageVersion = $page->allVersions('', '', 1); // get the original version if ($pageVersion && $pageVersion->count()) { $existing[] = $pageVersion->first()->Author()->Email; } } } }
将 CommentNotificationExtension
应用到任何启用了评论的类(例如 SiteTree)
mysite/_config/extensions.yml
SilverStripe\CMS\Model\SiteTree: extensions: - CommentNotificationExtension