You are here

public function Memory::send in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php \Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::send()
  2. 2.1.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php \Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::send()

Sends an SMS.

Parameters

\Drupal\sms\Message\SmsMessageInterface $sms: The sms to be sent.

Return value

\Drupal\sms\Message\SmsMessageResultInterface The result of the sms messaging operation.

Overrides SmsGatewayPluginInterface::send

2 calls to Memory::send()
MemoryOutgoingResult::send in tests/modules/sms_test_gateway/src/Plugin/SmsGateway/MemoryOutgoingResult.php
Sends an SMS.
ScheduleAware::send in tests/modules/sms_test_gateway/src/Plugin/SmsGateway/ScheduleAware.php
Sends an SMS.
2 methods override Memory::send()
MemoryOutgoingResult::send in tests/modules/sms_test_gateway/src/Plugin/SmsGateway/MemoryOutgoingResult.php
Sends an SMS.
ScheduleAware::send in tests/modules/sms_test_gateway/src/Plugin/SmsGateway/ScheduleAware.php
Sends an SMS.

File

tests/modules/sms_test_gateway/src/Plugin/SmsGateway/Memory.php, line 72

Class

Memory
Defines a gateway storing transmitted SMS in memory.

Namespace

Drupal\sms_test_gateway\Plugin\SmsGateway

Code

public function send(SmsMessageInterface $sms_message) {
  $gateway_id = $this->configuration['gateway_id'];

  // Message.
  $state = \Drupal::state()
    ->get('sms_test_gateway.memory.send', []);
  $state[$gateway_id][] = $sms_message;
  \Drupal::state()
    ->set('sms_test_gateway.memory.send', $state);

  // Reports.
  $reports = \Drupal::state()
    ->get('sms_test_gateway.memory.report', []);
  $gateway_reports = isset($reports[$gateway_id]) ? $reports[$gateway_id] : [];
  $new_reports = $this
    ->randomDeliveryReports($sms_message);
  $reports[$gateway_id] = array_merge($gateway_reports, $new_reports);
  \Drupal::state()
    ->set('sms_test_gateway.memory.report', $reports);
  return (new SmsMessageResult())
    ->setReports($new_reports);
}