silverstripe-australia / notifications
4.6.3
2020-05-25 02:00 UTC
Requires
- php: >=5.6.0
- silverstripe/framework: ^4.0
- symbiote/silverstripe-multivaluefield: ^5.0
Requires (Dev)
- phpunit/phpunit: ^5
Suggests
- symbiote/silverstripe-queuedjobs: Use the SendNotificationJob to queue and send notifications.
Replaces
- 4.6.3
- 4.6.2
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.1
- 4.4.0
- dev-master / 4.3.x-dev
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.1
- 4.0.0
- 2.0.x-dev
- 2.0.1
- 2.0.0
- 1.0.x-dev
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.0
- dev-fix-seen-read
- dev-fix-broadcast-notifications
- dev-fix-context-values
- dev-feature-read-extension
- dev-fix-notifyon
- dev-fix-internal-sender
- dev-fix-invalid-classinfo-call
- dev-fix-system-notification
- dev-nyeholt-patch-1
- dev-feature-broadcast-notification
- dev-feature-IsSeen
- dev-fix-missing-emails
- dev-feature-NotifyService
This package is not auto-updated.
Last update: 2020-09-10 10:23:33 UTC
README
从代码发送CMS管理的系统电子邮件通知。
维护者联系方式
- Marcus Nyeholt (marcus@symbiote.com.au)
- Shea Dawson (shea@symbiote.com.au)
要求
- SilverStripe 4.0 +
安装说明
composer require symbiote/silverstripe-notifications
发送通知
该模块包含一个默认的BroadcastNotification对象,可以用来一次性发送通知给多个人。首先,创建SystemNotification(定义了如何发送通知)
通知 => 添加系统通知
- 标识符: BROADCAST
- 标题: (您的标题)
- 相关于: BroadcastNotification
- 通过渠道发送: 内部
- 文本: (您的文本;使用$Context.Content输出广播内容)
通知 => 添加广播通知
- 标题: (您的标题)
- 内容: (您的文本)
- 点击创建
- 组: 选择接收通知的组
- 现在发送: 准备发送时点击。
创建系统通知
创建自定义通知需要一些代码来组合。以下以BroadcastNotification为例,并标识了关键点。
1)
在您的_config.yml文件中,为所需的每个通知添加一个标识符。这允许您从代码中在数据库中查找Notification对象。
Symbiote\Notifications\Model\SystemNotification:
identifiers:
- 'NAME_OF_NOTIFICATION1'
- 'NAME_OF_NOTIFICATION2'
2)
将NotifiedOn接口添加到任何相关的数据对象上。这是必需的,以便通知模块可以在您的对象上查找以下方法以发送通知。
use Symbiote\Notifications\Model\NotifiedOn; class MyDataObject extends DataObject implements NotifiedOn { ...
在正在通知的对象上定义以下接口方法。
/** * Return a list of available keywords in the format * array('keyword' => 'A description') to help users format notification fields * @return array */ public function getAvailableKeywords();
/** * Gets an associative array of data that can be accessed in * notification fields and templates * @return array */ public function getNotificationTemplateData();
注意:以下模板数据是自动包含的
- $ThemeDirs(一个包含主题的ArrayList对象,如果您只有一个主题,使用
$ThemeDirs.First
应该与旧的$ThemeDir
相同) - $SiteConfig
- $MyDataObject(您的NotifiedOn数据对象的ClassName)
- $Member(接收此消息的Member对象)
/** * Gets the list of recipients for a given notification event, based on this object's * state. * $event The identifier of the event that triggered this notification * @return array An array of Member objects */ public function getRecipients($event);
注意:getRecipients()可以返回任何具有Email属性或方法的对象数组
3)
在CMS的通知模型管理器中创建通知。
4)
从您的代码发送通知,其中$contextObject是正在通知的数据对象的一个实例
use Symbiote\Notifications\Service\NotificationService; singleton(NotificationService::class)->notify('NOTIFICATION_IDENTIFIER', $contextObject);
模板
通知可以使用 .ss 模板进行渲染。如果您想在电子邮件通知中包含页眉/页脚,这将非常有用。您可以在CMS中为每个/每个通知指定一个模板,并且/或者为所有要渲染的通知设置一个默认模板
Symbiote\Notifications\Model\SystemNotification:
default_template: EmailNotification
在您的模板中,您可以使用 $Body 变量来渲染通知文本。
配置
您可能想要配置一个发送者电子邮件地址 -
Symbiote\Notifications\Service\EmailNotificationSender:
send_notifications_from: 'notifications@example.com'
待办事项
- 使用配置的批次/队列处理大量通知的 QueuedJobs 模块进行测试