You are here

public function ClientManager::resetConnection in Acquia Content Hub 8

Resets the connection to allow to pass connection variables.

This should be used when we need to pass connection variables instead of using the ones stored in Drupal variables.

Parameters

array $variables: The array of variables to pass through.

array $config: The Configuration options.

Overrides ClientManagerInterface::resetConnection

File

src/Client/ClientManager.php, line 172

Class

ClientManager
Provides a service for managing pending server tasks.

Namespace

Drupal\acquia_contenthub\Client

Code

public function resetConnection(array $variables, array $config = []) {

  // Manually pass in the api/secret keys to the middlewares.
  $api = $variables['api'] ?? '';
  $secret = $variables['secret'] ?? '';
  foreach ($this->collector
    ->getMiddlewares() as $middleware) {
    $middleware
      ->setApiKey($api);
    $middleware
      ->setSecretKey($secret);
  }

  // If not overwritten, these should use the same configured variables.
  $hostname = $variables['hostname'] ?? $this->config
    ->get('hostname');
  $origin = $variables['origin'] ?? $this->config
    ->get('origin');

  // Override configuration.
  $config = array_merge([
    'base_url' => $hostname,
    'client-user-agent' => $this->clientUserAgent,
    'adapterConfig' => [
      'schemaId' => 'Drupal8',
      'defaultLanguageId' => $this->languageManager
        ->getDefaultLanguage()
        ->getId(),
    ],
  ], $config);
  $this->client = new ContentHub($origin, $this->collector
    ->getMiddlewares(), $config);
}