You are here

public function SmsDevelMessageForm::submitSend 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.

File

modules/sms_devel/src/Form/SmsDevelMessageForm.php, line 221

Class

SmsDevelMessageForm
Simulate a message being sent or received.

Namespace

Drupal\sms_devel\Form

Code

public function submitSend(array &$form, FormStateInterface $form_state) {
  $this->message
    ->setDirection(Direction::OUTGOING);
  try {
    $skip_queue = $form_state
      ->getValue('skip_queue');
    $verbose = $form_state
      ->getValue('verbose');
    if ($verbose && $skip_queue) {
      $messages = $this->smsProvider
        ->send($this->message);
      $results = [];
      foreach ($messages as $message) {
        $result = $message
          ->getResult();
        $this
          ->resultMessage($result);
        $results[] = $result;
      }
      $form_state
        ->setTemporaryValue('results', $results);
      $form_state
        ->setRebuild();
    }
    else {
      $this->smsProvider
        ->queue($this->message);
      drupal_set_message($this
        ->t('Message added to the outgoing queue.'));
    }
  } catch (SmsException $e) {
    drupal_set_message($this
      ->t('Message could not be sent: @error', [
      '@error' => $e
        ->getMessage(),
    ]), 'error');
  }
}