public function SendToPhoneForm::submitForm in SMS Framework 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/sms_sendtophone/ src/ Form/ SendToPhoneForm.php, line 167 
Class
- SendToPhoneForm
- Default controller for the sms_sendtophone module.
Namespace
Drupal\sms_sendtophone\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
  $user = User::load($this
    ->currentUser()
    ->id());
  $number = $form_state
    ->getValue('number');
  $message = $form_state
    ->getValue('message');
  $sms_message = SmsMessage::create()
    ->setDirection(Direction::OUTGOING)
    ->setMessage($message)
    ->setSenderEntity($user)
    ->addRecipient($number);
  try {
    $this->smsProvider
      ->queue($sms_message);
    drupal_set_message($this
      ->t('Message has been sent.'));
  } catch (\Exception $e) {
    drupal_set_message($this
      ->t('Message could not be sent: @error', [
      '@error' => $e
        ->getMessage(),
    ]), 'error');
  }
}