You are here

public function BynderConfigurationForm::testConnectionAjaxCallback in Bynder 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::testConnectionAjaxCallback()
  2. 8 src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::testConnectionAjaxCallback()
  3. 4.0.x src/Form/BynderConfigurationForm.php \Drupal\bynder\Form\BynderConfigurationForm::testConnectionAjaxCallback()

AJAX callback for test connection button.

File

src/Form/BynderConfigurationForm.php, line 359

Class

BynderConfigurationForm
Configure bynder to enable OAuth based access.

Namespace

Drupal\bynder\Form

Code

public function testConnectionAjaxCallback(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $return_markup = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#attributes' => [
      'id' => 'connection-test',
    ],
  ];
  $credentials = $form_state
    ->getValue('credentials');
  if ($this
    ->testApiConnection($credentials['consumer_key'], $credentials['consumer_secret'], $credentials['token'], $credentials['token_secret'], $credentials['account_domain'])) {
    $return_markup['#value'] = $this
      ->t('The API connection was established successfully.');
    $return_markup['#attributes']['style'] = 'color: green;';
  }
  else {
    $return_markup['#value'] = $this
      ->t('Could not establish connection with Bynder. Check your credentials or <a href=":support">contact support.</a>', [
      ':support' => 'mailto:support@getbynder.com',
    ]);
    $return_markup['#attributes']['style'] = 'color: red;';
  }
  $response
    ->addCommand(new ReplaceCommand('#connection-test', $this->renderer
    ->render($return_markup)));
  return $response;
}