You are here

public function SmsMessageProcessor::ensureRecipients in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureRecipients()
  2. 2.1.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureRecipients()

Ensures there is at least one recipient on the message.

Parameters

\Drupal\sms\Event\SmsMessageEvent $event: The SMS message preprocess event.

File

src/EventSubscriber/SmsMessageProcessor.php, line 143

Class

SmsMessageProcessor
Handles messages before they are processed by queue(), send(), or incoming().

Namespace

Drupal\sms\EventSubscriber

Code

public function ensureRecipients(SmsMessageEvent $event) {
  $sms_messages = $event
    ->getMessages();
  foreach ($sms_messages as $sms_message) {
    if ($sms_message
      ->getDirection() == Direction::OUTGOING) {
      $recipients = $sms_message
        ->getRecipients();
      if (!count($recipients)) {
        throw new RecipientRouteException(sprintf('There are no recipients.'));
      }
    }
  }
}