You are here

public function ContentHubSettingsForm::submitForm in Acquia Content Hub 8.2

Same name and namespace in other branches
  1. 8 src/Form/ContentHubSettingsForm.php \Drupal\acquia_contenthub\Form\ContentHubSettingsForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/ContentHubSettingsForm.php, line 381

Class

ContentHubSettingsForm
Defines the form to configure the Content Hub connection settings.

Namespace

Drupal\acquia_contenthub\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);

  // We assume here all inserted values have passed validation.
  $this->settings = $this->client
    ->getSettings();
  $hostname = rtrim($this->settings
    ->getUrl(), '/');
  $remote = $this->client
    ->getRemoteSettings();
  $config = $this
    ->config('acquia_contenthub.admin_settings')
    ->set('hostname', $hostname)
    ->set('api_key', $this->settings
    ->getApiKey())
    ->set('secret_key', $this->settings
    ->getSecretKey())
    ->set('origin', $this->settings
    ->getUuid())
    ->set('client_name', $this->settings
    ->getName());
  if (isset($remote['shared_secret'])) {
    $config
      ->set('shared_secret', $remote['shared_secret']);
  }

  // Call Save now, so when the webhook call from Plexus occurs, we can
  // respond with a valid signature.
  $config
    ->save();

  // If a webhook was sent during registration, lets get that added as
  // well, return the webhook UUID if successful.
  $webhook = $form_state
    ->getValue('webhook');
  $response = $this->chConnectionManager
    ->registerWebhook($webhook);
  if (empty($response)) {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Registration to Content Hub was successful, but Content Hub could not reach your site to verify connectivity. Please update your publicly accessible URL and try again.'));
    return;
  }
}