public function FirebaseNotificationService::send in Firebase Push Notification (FCM) 8
Prepare to send notification.
Parameters
string|array $token: The device token.
array $param: Params for building message to FCM.
File
- src/
Service/ FirebaseNotificationService.php, line 40
Class
- FirebaseNotificationService
- Service for support code from previous module version.
Namespace
Drupal\firebase\ServiceCode
public function send($token, array $param) {
$options = [];
$notification = [];
// Collect all data to arrays for sending to new message service.
if (!isset($param['priority'])) {
$options['priority'] = 'high';
}
if (isset($param['icon'])) {
$notification['icon'] = $param['icon'];
}
if (isset($param['sound'])) {
$notification['sound'] = $param['sound'];
}
if (isset($param['click_action'])) {
$notification['click_action'] = $param['click_action'];
}
if (isset($param['badge'])) {
$notification['badge'] = $param['badge'];
}
if (isset($param['content_available'])) {
$options['content_available'] = $param['content_available'];
}
if (!empty($param['title']) && !empty($param['body'])) {
$notification += [
'title' => $param['title'],
'body' => $param['body'],
];
}
$this->messageService
->setRecipients($token);
$this->messageService
->setOptions($options);
$this->messageService
->setNotification($notification);
if (isset($param['data'])) {
$this->messageService
->setData($param['data']);
}
$this->messageService
->send();
}