You are here

public static function SmsMessage::convertFromSmsMessage in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::convertFromSmsMessage()
  2. 2.1.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::convertFromSmsMessage()

Converts a standard SMS message object to a SMS message entity.

Parameters

\Drupal\sms\Message\SmsMessageInterface $sms_message: A standard SMS message.

Return value

static An unsaved SMS Message entity.

3 calls to SmsMessage::convertFromSmsMessage()
DefaultSmsProvider::queue in src/Provider/DefaultSmsProvider.php
Queue a SMS message for sending or receiving.
SmsFrameworkMessageEntityTest::testConvertToEntityFromEntitySmsMessage in tests/src/Kernel/SmsFrameworkMessageEntityTest.php
Ensure there is no data loss if an entity is passed to the converter.
SmsFrameworkMessageEntityTest::testConvertToEntityFromStandardSmsMessage in tests/src/Kernel/SmsFrameworkMessageEntityTest.php
Ensure data from standard SMS message are passed to SMS message entity.

File

src/Entity/SmsMessage.php, line 582

Class

SmsMessage
Defines the SMS message entity.

Namespace

Drupal\sms\Entity

Code

public static function convertFromSmsMessage(StdSmsMessageInterface $sms_message) {
  if ($sms_message instanceof static) {
    return $sms_message;
  }
  $new = static::create();
  $new
    ->setDirection($sms_message
    ->getDirection())
    ->setAutomated($sms_message
    ->isAutomated())
    ->setSender($sms_message
    ->getSender())
    ->setSenderNumber($sms_message
    ->getSenderNumber())
    ->addRecipients($sms_message
    ->getRecipients())
    ->setMessage($sms_message
    ->getMessage())
    ->setResult($sms_message
    ->getResult());
  if ($gateway = $sms_message
    ->getGateway()) {
    $new
      ->setGateway($gateway);
  }
  if ($uid = $sms_message
    ->getUid()) {
    $new
      ->setUid($uid);
  }
  foreach ($sms_message
    ->getOptions() as $k => $v) {
    $new
      ->setOption($k, $v);
  }
  return $new;
}