Download the PHP package symbiote/silverstripe-notifications without Composer
On this page you can find all versions of the php package symbiote/silverstripe-notifications. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download symbiote/silverstripe-notifications
More information about symbiote/silverstripe-notifications
Files in symbiote/silverstripe-notifications
Package silverstripe-notifications
Short Description Send CMS editable system notifications from code
License BSD-3-Clause
Informations about the package silverstripe-notifications
SilverStripe Notifications Module
Send CMS managed system email notifications from code.
Maintainer Contacts
- Marcus Nyeholt ([email protected])
- Shea Dawson ([email protected])
Requirements
- SilverStripe 4.0 +
Installation Instructions
Sending a notification
The module comes with a default BroadcastNotification object that can be used to send a notification to multiple people at once. First, create the SystemNotification (which defines how the notification will be sent)
Notifications => Add System Notification
- Identifier: BROADCAST
- Title: (your own)
- Relevant For: BroadcastNotification
- Send via channels: Internal
- Text: (Your own; use $Context.Content to output the broadcast content)
Notifications => Add Broadcast Notification
- Title: (your own)
- Content: (your own)
- Click Create
- Groups: choose which groups to receive the notification
- Send Now: Click when ready for the notification to send.
Creating System Notifications
Creating custom notifications requires a few pieces of code to put things together. Use the BroadcastNotification as an example, with the key points identified below
1)
In your _config yml file, add an identifier for each notification you require. This allows you to lookup Notification objects in the database from your code.
2)
Add the NotifiedOn interface to any dataobjects that are relevant to the notifications you will be sending. This is required so the Notifications module can look up the below methods on your object to send the notification.
Define the following interface methods on the Object being notified on.
Note: the follow template data is automatically included:
- $ThemeDirs (an ArrayList object of themes, if you only have one theme using
$ThemeDirs.First
should be the same as the old$ThemeDir
) - $SiteConfig
- $MyDataObject (whatever the ClassName of your NotifiedOn DataObject is)
- $Member (The Member object this message is being sent to)
Note: getRecipients() can return an array of any objects, as long as they have an Email property or method
3)
Create a notification in the Notifications model admin, in the CMS.
4)
Send the notification from your code, where $contextObject is an instance of the DataObject being NotifiedOn
Templates
Notifications can be rendered with .ss templates. This is useful if you want to have a header/footer in your email notifications. You can either specify a template on a per/notification basis in the CMS, and/or set a default template for all notifications to be rendered with:
In your templates, you render the notification text with the $Body variable.
Configuration
You will probably want to configure a send_from email address -
TODO
- Test with QueuedJobs module for handling large amounts of notifications in configurable batches/queues
All versions of silverstripe-notifications with dependencies
silverstripe/framework Version ^4.0
symbiote/silverstripe-multivaluefield Version ^5.0