You are here

public function SettingsForm::testConnection in BigBlueButton 8

Test connection to Big Blue Button.

File

src/Form/SettingsForm.php, line 134

Class

SettingsForm
Provides an administration settings form.

Namespace

Drupal\bbb\Form

Code

public function testConnection($form, FormStateInterface $form_state) {
  $response = simplexml_load_file($form_state
    ->getValue([
    'bbb_server',
    'base_url',
  ]) . 'api/');
  if (!$response) {
    $content = $this
      ->t('Bad connection');
  }
  else {
    $link = Url::fromUri('https://mconf.github.io/api-mate/', [
      'fragment' => http_build_query([
        'server' => $form_state
          ->getValue([
          'bbb_server',
          'base_url',
        ]),
        'sharedSecret' => $form_state
          ->getValue([
          'bbb_server',
          'security_salt',
        ]),
      ]),
    ])
      ->toString();
    $content = $this
      ->t('Good connection.<br />Status: <em>@status</em><br />Version: <em>@version</em><br /><a href="@link" target="_blank">Link to the API-Mate</a>', [
      '@status' => $response->returncode,
      '@version' => $response->version,
      '@link' => $link,
    ]);
    $content .= '<br /><iframe src="' . $link . '" style="width: 100%; min-height: 50vh" frameborder="0"></iframe>';
  }
  $commands = new AjaxResponse();
  $commands
    ->addCommand(new OpenModalDialogCommand($this
    ->t('Test connection'), $content, [
    'width' => "90%",
  ]));
  return $commands;
}