You are here

public function ContentHubDeleteClientConfirmForm::submitForm in Acquia Content Hub 8.2

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 FormInterface::submitForm

File

src/Form/ContentHubDeleteClientConfirmForm.php, line 217

Class

ContentHubDeleteClientConfirmForm
Class ContentHubDeleteClientConfirmForm.

Namespace

Drupal\acquia_contenthub\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getTriggeringElement()['#name'] === 'subscription') {
    $form_state
      ->setRedirect('acquia_contenthub.subscription_settings');
    return;
  }
  if ($form_state
    ->getTriggeringElement()['#name'] === 'settings') {
    $form_state
      ->setRedirect('acquia_contenthub.admin_settings');
    return;
  }
  $client = $this->clientFactory
    ->getClient();
  if (!$client) {
    $this
      ->messenger()
      ->addError("Couldn't instantiate client. Please check connection settings.");
    $form_state
      ->setRedirect('acquia_contenthub.admin_settings');
    return;
  }
  try {
    $this->chConnectionManager
      ->unregister($this->event);
  } catch (\Exception $e) {
    $this
      ->messenger()
      ->addError($this
      ->t('Error during unregistration: @error_message', [
      '@error_message' => $e
        ->getMessage(),
    ]));
    return;
  }
  $form_state
    ->setRedirect('acquia_contenthub.admin_settings');
}