You are here

public function FirebaseMessageService::setOptions in Firebase Push Notification (FCM) 8

Same name and namespace in other branches
  1. 3.0.x src/Service/FirebaseMessageService.php \Drupal\firebase\Service\FirebaseMessageService::setOptions()

Add options to message.

Parameters

array $options: Message options.

See also

https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstr...

File

src/Service/FirebaseMessageService.php, line 115

Class

FirebaseMessageService
Service for pushing message to mobile devices using Firebase.

Namespace

Drupal\firebase\Service

Code

public function setOptions(array $options) {
  if (isset($options['priority']) && in_array(strtolower($options['priority']), [
    'high',
    'normal',
  ])) {
    $this->body['priority'] = $options['priority'];
  }
  if (isset($options['content_available'])) {
    $this->body['content_available'] = (bool) $options['content_available'];
  }
  if (isset($options['mutable_content'])) {
    $this->body['mutable_content'] = (bool) $options['mutable_content'];
  }
  if (isset($options['time_to_live']) && ((int) $options['time_to_live'] >= 0 && (int) $options['time_to_live'] <= 2419200)) {
    $this->body['time_to_live'] = $options['time_to_live'];
  }
  if (isset($options['dry_run'])) {
    $this->body['dry_run'] = (bool) $options['dry_run'];
  }
}