You are here

function drush_acquia_contenthub_connect_site in Acquia Content Hub 8

Connects a site with Content Hub.

File

./acquia_contenthub.drush.inc, line 744
ContentHub Drush Commands.

Code

function drush_acquia_contenthub_connect_site($api_key = '', $secret = '', $hostname = '', $client_name = '') {
  $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)) {
    drush_log(dt('Site is already connected to Content Hub. Skipping.'), LogLevel::CANCEL);
    return;
  }
  $hostname = !empty($hostname) ? $hostname : drush_prompt(dt('What is the Content Hub API URL?'), 'https://us-east-1.content-hub.acquia.com');
  $api_key = !empty($api_key) ? $api_key : drush_prompt(dt('What is your Content Hub API Key?'));
  $secret = !empty($secret) ? $secret : drush_prompt(dt('What is your Content Hub API Secret?'));
  $client_uuid = $uuid_service
    ->generate();
  $client_name = !empty($client_name) ? $client_name : drush_prompt(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);
}