You are here

public function PushNotificationsMessageSenderBase::dispatch in Push Notifications 8

Dispatch an alert.

File

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

Class

PushNotificationsMessageSenderBase
Handles sending of alerts.

Namespace

Drupal\push_notifications

Code

public function dispatch() {

  // Verify that message is set.
  if (empty($this->message)) {
    throw new \Exception('Message was not set correctly.');
  }

  // Generate tokens.
  $this
    ->generateTokens();

  // Log message if no tokens are available.
  if (empty($this->tokens)) {
    \Drupal::logger('push_notifications')
      ->notice('No tokens found.');
    return false;
  }

  // Generate and dispatch message.
  $this->dispatcher
    ->setMessage($this->message);
  $this->dispatcher
    ->setTokens($this->tokens);
  $this->dispatcher
    ->dispatch();
  $this->results = $this->dispatcher
    ->getResults();
}