You are here

public function AcquiaContenthubCommands::contenthubConnectSite in Acquia Content Hub 8

Connects a site with contenthub.

@command acquia:contenthub-connect-site @aliases ach-connect,acquia-contenthub-connect-site

@option hostname Content Hub API URL. @option api_key Content Hub API Key. @option secret Content Hub API Secret. @option client_name The client name for this site.

Parameters

array $options:

File

src/Commands/AcquiaContenthubCommands.php, line 563

Class

AcquiaContenthubCommands
A Drush commandfile.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function contenthubConnectSite(array $options = [
  'hostname' => NULL,
  'api_key' => NULL,
  'secret' => NULL,
  'client_name' => NULL,
]) {
  $config_factory = \Drupal::configFactory();
  $uuid_service = \Drupal::service('uuid');
  $config = $config_factory
    ->getEditable('acquia_contenthub.admin_settings');
  $config_api_key = $config
    ->get('api_key');
  if (!empty($config_api_key)) {
    $this
      ->logger()
      ->log(LogLevel::CANCEL, dt('Site is already connected to Content Hub. Skipping.'));
    return;
  }
  $hostname = !empty($options['hostname']) ? $options['hostname'] : $this
    ->io()
    ->ask(dt('What is the Content Hub API URL?'), 'https://us-east-1.content-hub.acquia.com');
  $api_key = !empty($options['api_key']) ? $options['api_key'] : $this
    ->io()
    ->ask(dt('What is your Content Hub API Key?'));
  $secret = !empty($options['secret']) ? $options['secret'] : $this
    ->io()
    ->ask(dt('What is your Content Hub API Secret?'));
  $client_uuid = $uuid_service
    ->generate();
  $client_name = !empty($options['client_name']) ? $options['client_name'] : $this
    ->io()
    ->ask(dt('What is the client name for this site?'), $client_uuid);
  $form_state = new FormState();
  $values['api_key'] = $api_key;
  $values['secret_key'] = $secret;
  $values['hostname'] = $hostname;
  $values['client_name'] = $client_name . '_' . $client_uuid;
  $values['op'] = t('Save configuration');
  $form_state
    ->setValues($values);
  \Drupal::formBuilder()
    ->submitForm('Drupal\\acquia_contenthub\\Form\\ContentHubSettingsForm', $form_state);
}