You are here

public function SendTestMessageForm::submitForm in Slack 8

Throws

\GuzzleHttp\Exception\GuzzleException

Overrides FormInterface::submitForm

File

src/Form/SendTestMessageForm.php, line 86

Class

SendTestMessageForm
Class SendTestMessageForm.

Namespace

Drupal\slack\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (empty($form_state
    ->getRedirect())) {
    $config = $this
      ->config('slack.settings');
    $channel = $form_state
      ->getValue('slack_test_channel');
    $message = $form_state
      ->getValue('slack_test_message');
    $username = $config
      ->get('slack_username');
    $response = $this->slackService
      ->sendMessage($message, $channel, $username);
    if ($response && RedirectResponse::HTTP_OK == $response
      ->getStatusCode()) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('Message was successfully sent!'));
    }
    else {
      $this
        ->messenger()
        ->addWarning($this
        ->t('Please check log messages for further details'));
    }
  }
}