public function AcquiaContentHubSiteCommands::contenthubConnectSite in Acquia Content Hub 8.2
Connects a site with contenthub.
@command acquia:contenthub-connect-site @aliases ach-connect,acquia-contenthub-connect-site
@option $hostname Content Hub API URL. @default $hostname null
@option $api_key Content Hub API Key. @default $api_key null
@option $secret_key Content Hub API Secret. @default $secret_key null
@option $client_name The client name for this site. @default $client_name null
@usage ach-connect hostname, api_key, secret_key, client_name will be requested. @usage ach-connect --hostname=https://us-east-1.content-hub.acquia.com api_key, secret_key, client_name will be requested. @usage ach-connect --hostname=https://us-east-1.content-hub.acquia.com --api_key=API_KEY --secret_key=SECRET_KEY --client_name=CLIENT_NAME Connects site with following credentials.
File
- src/
Commands/ AcquiaContentHubSiteCommands.php, line 90
Class
- AcquiaContentHubSiteCommands
- Drush commands for interacting with Acquia Content Hub client site.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubConnectSite() {
$options = $this
->input()
->getOptions();
// @todo Revisit initial connection logic with our event subscibers.
$settings = $this->clientFactory
->getSettings();
$config_origin = $settings
->getUuid();
$provider = $this->clientFactory
->getProvider();
if ($provider != 'core_config') {
$message = dt('Settings are being provided by @provider, and already connected.', [
'@provider' => $provider,
]);
$this
->logger()
->log(LogLevel::CANCEL, $message);
return;
}
if (!empty($config_origin)) {
$message = dt('Site is already connected to Content Hub. Skipping.');
$this
->logger()
->log(LogLevel::CANCEL, $message);
return;
}
$io = $this
->io();
$hostname = $options['hostname'] ?? $io
->ask(dt('What is the Content Hub API URL?'), 'https://us-east-1.content-hub.acquia.com');
$api_key = $options['api_key'] ?? $io
->ask(dt('What is your Content Hub API Key?'));
$secret_key = $options['secret_key'] ?? $io
->ask(dt('What is your Content Hub API Secret?'));
$client_uuid = \Drupal::service('uuid')
->generate();
$client_name = $options['client_name'] ?? $io
->ask(dt('What is the client name for this site?'), $client_uuid);
$form_state = (new FormState())
->setValues([
'hostname' => $hostname,
'api_key' => $api_key,
'secret_key' => $secret_key,
'client_name' => sprintf("%s_%s", $client_name, $client_uuid),
'op' => t('Save configuration'),
]);
// @todo Errors handling can be improved after relocation of registration
// logic into separate service.
$form = \Drupal::formBuilder()
->buildForm(ContentHubSettingsForm::class, new FormState());
$form_state
->setTriggeringElement($form['actions']['submit']);
\Drupal::formBuilder()
->submitForm(ContentHubSettingsForm::class, $form_state);
}