You are here

public function ApiTestForm::submitForm in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 modules/rocket_chat_api_test/src/Form/ApiTestForm.php \Drupal\rocket_chat_api_test\Form\ApiTestForm::submitForm()

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/rocket_chat_api_test/src/Form/ApiTestForm.php, line 156
Contains \Drupal\rocket_chat_api_test\Form\ApiTestForm.

Class

ApiTestForm
Class RocketChatSettingsForm.

Namespace

Drupal\rocket_chat_api_test\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $apiConfig = new Drupal8Config($this->configFactory, $this->moduleHandler, $this->state);
  $apiClient = new ApiClient($apiConfig);
  switch ($form_state
    ->getValue('verb')) {
    case "GET":
      $options = [
        'query' => Json::decode($form_state
          ->getValue('Options')),
      ];
      $result = $apiClient
        ->getFromRocketChat($form_state
        ->getValue('method'), $options);
      break;
    case "POST":
      $options = [
        'json' => Json::decode($form_state
          ->getValue('Options')),
      ];
      $result = $apiClient
        ->postToRocketChat($form_state
        ->getValue('method'), $options);
      break;
    default:
      $result = [
        "status" => "ILLEGAL ACTION",
        "body" => "NULL",
      ];
      break;
  }
  drupal_set_message($result['status'] . ': ' . var_export($result['body'], TRUE));
}