You are here

public function MemoryOutgoingResult::send in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/MemoryOutgoingResult.php \Drupal\sms_test_gateway\Plugin\SmsGateway\MemoryOutgoingResult::send()
  2. 2.1.x tests/modules/sms_test_gateway/src/Plugin/SmsGateway/MemoryOutgoingResult.php \Drupal\sms_test_gateway\Plugin\SmsGateway\MemoryOutgoingResult::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 Memory::send

File

tests/modules/sms_test_gateway/src/Plugin/SmsGateway/MemoryOutgoingResult.php, line 21

Class

MemoryOutgoingResult
Defines a gateway with defective return values for its' send method.

Namespace

Drupal\sms_test_gateway\Plugin\SmsGateway

Code

public function send(SmsMessageInterface $sms_message) {
  $result = parent::send($sms_message);
  if (\Drupal::state()
    ->get('sms_test_gateway.memory_outgoing_result.missing_result')) {
    return NULL;
  }
  $delete_reports = \Drupal::state()
    ->get('sms_test_gateway.memory_outgoing_result.delete_reports');
  if ($delete_reports > 0) {
    $reports = $result
      ->getReports();
    if (!count($reports)) {
      throw new \Exception('There are no reports to delete.');
    }

    // Slice off the first {$delete_reports}x reports.
    $reports = array_slice($reports, $delete_reports);
    $result
      ->setReports($reports);
    return $result;
  }
  return $result;
}