You are here

private function AdminSettingsForm::setCredentialValues in Acquia Lift Connector 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/AdminSettingsForm.php \Drupal\acquia_lift\Form\AdminSettingsForm::setCredentialValues()
  2. 8 src/Form/AdminSettingsForm.php \Drupal\acquia_lift\Form\AdminSettingsForm::setCredentialValues()

Set credential values.

Parameters

\Drupal\Core\Config\Config $settings: Acquia Lift config settings.

array $values: Credential values.

1 call to AdminSettingsForm::setCredentialValues()
AdminSettingsForm::submitForm in src/Form/AdminSettingsForm.php
Form submission handler.

File

src/Form/AdminSettingsForm.php, line 509

Class

AdminSettingsForm
Defines a form that configures settings.

Namespace

Drupal\acquia_lift\Form

Code

private function setCredentialValues(Config $settings, array $values) {
  $settings
    ->set('credential.account_id', trim($values['account_id']));
  $settings
    ->set('credential.site_id', trim($values['site_id']));

  // Set Assets URL, also check its connection.
  $standardized_assets_url = 'https://' . $this
    ->cleanUrl($values['assets_url']);
  $settings
    ->set('credential.assets_url', $standardized_assets_url);
  $standardized_assets_url_parts = parse_url($standardized_assets_url);
  $standardized_assets_url_scheme = isset($standardized_assets_url_parts['scheme']) ? $standardized_assets_url_parts['scheme'] : '';
  $standardized_assets_url_host = isset($standardized_assets_url_parts['host']) ? $standardized_assets_url_parts['host'] : '';
  $standardized_assets_url_path = isset($standardized_assets_url_parts['path']) ? $standardized_assets_url_parts['path'] : '';
  $this
    ->checkConnection('Assets', $standardized_assets_url_scheme . '://' . $standardized_assets_url_host, $standardized_assets_url_path . '/lift.js');

  // If present, set Decision API URL, also check its connection.
  $settings
    ->clear('credential.decision_api_url');
  if (!empty($values['decision_api_url'])) {
    $standardized_decision_api_url = 'https://' . $this
      ->cleanUrl($values['decision_api_url']);
    $settings
      ->set('credential.decision_api_url', $standardized_decision_api_url);
    $this
      ->checkConnection('Decision API', $standardized_decision_api_url, '/admin/ping', 403);
  }

  // If present, set OAuth URL, also check its connection.
  $settings
    ->clear('credential.oauth_url');
  if (!empty($values['oauth_url'])) {
    $standardized_oauth_url = 'https://' . $this
      ->cleanUrl($this
      ->removeAuthorizeSuffix($values['oauth_url']));
    $settings
      ->set('credential.oauth_url', $standardized_oauth_url . '/authorize');
    $this
      ->checkConnection('Authentication', $standardized_oauth_url, '/ping');
  }
}