You are here

public function CredentialForm::submitForm in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Form/CredentialForm.php \Drupal\acquia_connector\Form\CredentialForm::submitForm()
  2. 3.x src/Form/CredentialForm.php \Drupal\acquia_connector\Form\CredentialForm::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/CredentialForm.php, line 141

Class

CredentialForm
Form for Acquia Credentials.

Namespace

Drupal\acquia_connector\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('acquia_connector.settings');
  $config
    ->set('subscription_name', $form_state
    ->getValue('subscription'))
    ->save();
  $storage = new Storage();
  $storage
    ->setKey($form_state
    ->getValue('acquia_key'));
  $storage
    ->setIdentifier($form_state
    ->getValue('acquia_identifier'));

  // Check subscription and send a heartbeat to Acquia via XML-RPC.
  // Our status gets updated locally via the return data.
  $subscription = new Subscription();
  $subscription_data = $subscription
    ->update();

  // Redirect to the path without the suffix.
  $form_state
    ->setRedirect('acquia_connector.settings');
  drupal_flush_all_caches();
  if ($subscription_data['active']) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('<h3>Connection successful!</h3>You are now connected to Acquia Cloud. Please enter a name for your site to begin sending profile data.'));
  }
}