You are here

public function SmsTestGatewayEventSubscriber::memoryIncomingMessage in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php \Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber::memoryIncomingMessage()
  2. 2.1.x tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php \Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber::memoryIncomingMessage()

Store incoming messages in memory.

Parameters

\Drupal\sms\Event\SmsMessageEvent $event: The event.

See also

sms_test_gateway_get_incoming()

File

tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php, line 22

Class

SmsTestGatewayEventSubscriber
Test event subscriber.

Namespace

Drupal\sms_test_gateway\EventSubscriber

Code

public function memoryIncomingMessage(SmsMessageEvent $event) {
  $sms_message = $event
    ->getMessages()[0];

  // Save incoming result for later retrieval.
  $key = 'sms_test_gateway_sms_incoming_preprocess';
  $result =& drupal_static($key);
  if (!is_null($sms_message
    ->getRecipients()) && !is_null($sms_message
    ->getMessage())) {
    $recipients = $sms_message
      ->getRecipients();
    $result['number'] = count($recipients) ? reset($recipients) : NULL;
    $result['message'] = $sms_message
      ->getMessage();
    \Drupal::state()
      ->set($key, $result);
  }
  $key = 'sms_test_gateway.memory.incoming';
  $incoming_messages =& drupal_static($key, []);
  foreach ($event
    ->getMessages() as $message) {

    /** @var \Drupal\sms\Message\SmsMessageInterface $message */
    $incoming_messages[$message
      ->getGateway()
      ->id()][] = $message;
  }
  \Drupal::state()
    ->set($key, $incoming_messages);
}