You are here

public function SmsMessageProcessor::chunkMaxRecipients in SMS Framework 2.x

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

Split messages to overcome gateway limits.

Parameters

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

File

src/EventSubscriber/SmsMessageProcessor.php, line 271

Class

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

Namespace

Drupal\sms\EventSubscriber

Code

public function chunkMaxRecipients(SmsMessageEvent $event) {
  $result = [];
  foreach ($event
    ->getMessages() as $sms_message) {
    if ($sms_message
      ->getDirection() == Direction::OUTGOING) {
      $max = $sms_message
        ->getGateway()
        ->getMaxRecipientsOutgoing();
      $result = array_merge($result, $sms_message
        ->chunkByRecipients($max));
    }
    else {
      $result[] = $sms_message;
    }
  }
  $event
    ->setMessages($result);
}