You are here

public function PhoneNumberProvider::sendMessage in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/Provider/PhoneNumberProvider.php \Drupal\sms\Provider\PhoneNumberProvider::sendMessage()
  2. 2.1.x src/Provider/PhoneNumberProvider.php \Drupal\sms\Provider\PhoneNumberProvider::sendMessage()

Sends an SMS to an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to send an SMS.

\Drupal\sms\Message\SmsMessageInterface $sms_message: The SMS message to send to the entity.

Return value

\Drupal\sms\Message\SmsMessageResultInterface|false The message result from the gateway.

Throws

\Drupal\sms\Exception\NoPhoneNumberException Thrown if entity does not have a phone number.

Overrides PhoneNumberProviderInterface::sendMessage

File

src/Provider/PhoneNumberProvider.php, line 60

Class

PhoneNumberProvider
Phone number provider.

Namespace

Drupal\sms\Provider

Code

public function sendMessage(EntityInterface $entity, SmsMessageInterface $sms_message) {
  if (!($phone_numbers = $this
    ->getPhoneNumbers($entity))) {
    throw new NoPhoneNumberException('Attempted to send an SMS to entity without a phone number.');
  }
  $sms_message = SmsMessageEntity::convertFromSmsMessage($sms_message)
    ->addRecipient(reset($phone_numbers))
    ->setRecipientEntity($entity)
    ->setDirection(Direction::OUTGOING);
  $this->smsProvider
    ->queue($sms_message);
}