You are here

public function PushNotificationsMessageSenderBase::setMessage in Push Notifications 8

Setter function for message.

Parameters

string $message Message to send.:

Throws

\Exception Message needs to be a string.

File

src/PushNotificationsMessageSenderBase.php, line 88
Contains \Drupal\push_notifications\PushNotificationsMessageSenderBase.

Class

PushNotificationsMessageSenderBase
Handles sending of alerts.

Namespace

Drupal\push_notifications

Code

public function setMessage($message) {
  if (!is_string($message)) {
    throw new \Exception('Message needs to be a string.');
  }

  // Allow other modules modify the message before it is sent.
  $implementations = \Drupal::moduleHandler()
    ->getImplementations('push_notifications_send_message');
  foreach ($implementations as $module) {
    $function = $module . '_push_notifications_send_message';
    $function($message, $type = 'simple');
  }

  // Truncate the message so that we don't exceed the limit of APNS.
  $this->message = Unicode::truncate($message, PUSH_NOTIFICATIONS_APNS_PAYLOAD_SIZE_LIMIT, TRUE, TRUE);
}