Technical Solution
[SOLVED] How To Create Custom Plugin In Notifier?
To implement push notification for a project, we first created a new custom plugin to push messages into a custom table. When the cron runs, the messages stored in the queue table will be processed and saved to the custom table. For this, create a new directory "push" in message_notify/plugins/notifier/ and use it just like email or sms. The directory may contain 2 files:
- push.inc
- MessageNotifierPush.class.php
In push.inc, create a plugin with class and view modes
$plugin = array(
'title' => t('Push'),
'description' => t('Send Message as notification.'),
'class' => 'MessageNotifierPush',
// A notifier must define its own view modes.
// Those view modes are later going to be rendered and sent.
'view_modes' => array(
'message_notify_push_body' => array('label' => t('Notify - Push body')),
),
);
The MessageNotifierPush.class.php extends MessageNotifierBase class and can be structured as:
class MessageNotifierPush extends MessageNotifierBase {
public function deliver(array $output = array()) {
$notification_text = strip_tags($output['message_notify_push_body']);
$message = $this->message;
// Get the message object and the notification text and pass it to the custom function
return abc_push($message, $notification_text);
}
}
In our custom function, abc_push function will fetch the details of message in the queue table.
function abc_push($message, $notification_text) {
$wrapper = entity_metadata_wrapper('message', $message);
$field_value = $wrapper->{field_name}->raw();
// Rest of the code here...
}
These field values are then saved to our database table. We can display these field values wherever needed.