You are here

public function SmsMessage::setResult in SMS Framework 8

Same name in this branch
  1. 8 src/Message/SmsMessage.php \Drupal\sms\Message\SmsMessage::setResult()
  2. 8 src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::setResult()
Same name and namespace in other branches
  1. 2.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::setResult()
  2. 2.1.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::setResult()

Sets the result associated with this SMS message.

Results on a saved SMS message are immutable and cannot be changed. An exception will be thrown if this method is called on an SmsMessage that already has saved results.

Parameters

\Drupal\sms\Message\SmsMessageResultInterface|null $result: The result to associate with this SMS message, or NULL if there is no result.

Return value

$this The called SMS message object.

Throws

\Drupal\sms\Exception\SmsStorageException If the SMS message entity already has saved results.

Overrides SmsMessageInterface::setResult

File

src/Entity/SmsMessage.php, line 180

Class

SmsMessage
Defines the SMS message entity.

Namespace

Drupal\sms\Entity

Code

public function setResult(StdMessageResultInterface $result = NULL) {

  // Throw an exception if there is already a result for this SMS message.
  $previous_result = $this
    ->getResult();
  if ($previous_result) {
    throw new SmsStorageException('Saved SMS message results cannot be changed or updated.');
  }
  elseif ($result) {

    // Temporarily store the result so it can be retrieved without having to
    // save the message entity.
    $this->result = $result;
  }
  return $this;
}