public function GetSettingsFromEnvVar::onGetSettings in Acquia Content Hub 8.2
Extract settings from environment and create a Settings object.
Parameters
\Drupal\acquia_contenthub\Event\AcquiaContentHubSettingsEvent $event: The dispatched event.
See also
\Acquia\ContentHubClient\Settings
File
- src/
EventSubscriber/ GetSettings/ GetSettingsFromEnvVar.php, line 79
Class
- GetSettingsFromEnvVar
- Gets the ContentHub Server settings from environment variable.
Namespace
Drupal\acquia_contenthub\EventSubscriber\GetSettingsCode
public function onGetSettings(AcquiaContentHubSettingsEvent $event) {
$credentials = [];
foreach (self::ENVIRONMENT_VARIABLES as $env_variable) {
$credential = getenv($env_variable);
if ($credential) {
$credentials[$env_variable] = $credential;
}
}
if (count($credentials) === 0) {
// If there are no environment variables set, then we should keep going
// and not log all the errors in isValidCredential(). We assume, the user
// do not want to use this way of registration.
return;
}
$success = $this
->isValidCredential($credentials);
if (!$success) {
return;
}
$settings = new Settings($credentials['acquia_contenthub_client_name'], $credentials['acquia_contenthub_origin'], $credentials['acquia_contenthub_api_key'], $credentials['acquia_contenthub_api_secret'], $credentials['acquia_contenthub_hostname'], $credentials['acquia_contenthub_shared_secret'], [
'url' => $credentials['acquia_contenthub_webhook_url'],
'uuid' => $credentials['acquia_contenthub_webhook_uuid'],
'settings_url' => $credentials['acquia_contenthub_settings_url'],
]);
$event
->setProvider('environment_variable');
$event
->setSettings($settings);
$event
->stopPropagation();
}