2017 © Pedro Peláez
 

silverstripe-module notifications

Send CMS editable system notifications from code

image

silverstripe-australia/notifications

Send CMS editable system notifications from code

  • Thursday, June 29, 2017
  • by nyeholt
  • Repository
  • 11 Watchers
  • 11 Stars
  • 1,350 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 6 Forks
  • 8 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

SilverStripe Notifications Module

Send CMS managed system email notifications from code., (*1)

Maintainer Contacts

Requirements

  • SilverStripe 4.0 +

Installation Instructions

composer require symbiote/silverstripe-notifications

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), (*2)

Notifications => Add System Notification, (*3)

  • 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, (*4)

  • 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, (*5)

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., (*6)

Symbiote\Notifications\Model\SystemNotification:
  identifiers:
    - 'NAME_OF_NOTIFICATION1'
    - 'NAME_OF_NOTIFICATION2'

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., (*7)

use Symbiote\Notifications\Model\NotifiedOn;

class MyDataObject extends DataObject implements NotifiedOn {
    ...

Define the following interface methods on the Object being notified on., (*8)

/**
 * Return a list of available keywords in the format 
 * array('keyword' => 'A description') to help users format notification fields
 * @return array
 */
public function getAvailableKeywords();

```php /** * Gets an associative array of data that can be accessed in * notification fields and templates * @return array */ public function getNotificationTemplateData();, (*9)


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) ```php /** * 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);

Note: getRecipients() can return an array of any objects, as long as they have an Email property or method, (*10)

3)

Create a notification in the Notifications model admin, in the CMS., (*11)

4)

Send the notification from your code, where $contextObject is an instance of the DataObject being NotifiedOn, (*12)

use Symbiote\Notifications\Service\NotificationService;

singleton(NotificationService::class)->notify('NOTIFICATION_IDENTIFIER', $contextObject);

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:, (*13)

Symbiote\Notifications\Model\SystemNotification:
  default_template: EmailNotification

In your templates, you render the notification text with the $Body variable., (*14)

Configuration

You will probably want to configure a send_from email address -, (*15)

Symbiote\Notifications\Service\EmailNotificationSender:
  send_notifications_from: 'notifications@example.com'

TODO

  • Test with QueuedJobs module for handling large amounts of notifications in configurable batches/queues

The Versions

29/06 2017

dev-master

9999999-dev

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

29/06 2017

2.0.1

2.0.1.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

23/06 2017

2.0.0

2.0.0.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

29/03 2016

1.0.3

1.0.3.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

14/09 2015

1.0.x-dev

1.0.9999999.9999999-dev

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

15/07 2015

1.0.2

1.0.2.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

28/02 2015

1.0.1

1.0.1.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

17/02 2015

1.0.0

1.0.0.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

30/05 2014

0.2.0

0.2.0.0

Send CMS editable system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications

27/05 2014

0.1.0

0.1.0.0

Send CMS managed system notifications from code

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe notifications