You are here

public function MiniorangeSAMLRemoveLicense::submitModalFormAjax in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8

File

src/Form/MiniorangeSAMLRemoveLicense.php, line 62

Class

MiniorangeSAMLRemoveLicense

Namespace

Drupal\miniorange_saml\Form

Code

public function submitModalFormAjax(array $form, FormStateInterface $form_state) {
  $editConfig = \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings');
  $response = new AjaxResponse();

  // If there are any form errors, AJAX replace the form.
  if ($form_state
    ->hasAnyErrors()) {
    $response
      ->addCommand(new ReplaceCommand('#modal_example_form', $form));
  }
  else {
    $editConfig
      ->clear('miniorange_saml_license_key')
      ->clear('miniorange_saml_customer_admin_email')
      ->clear('miniorange_saml_customer_admin_phone')
      ->clear('miniorange_saml_customer_id')
      ->clear('miniorange_saml_customer_api_key')
      ->clear('miniorange_saml_customer_admin_token')
      ->set('miniorange_saml_status', 'CUSTOMER_SETUP')
      ->save();
    \Drupal::messenger()
      ->addMessage(t('Your Account Has Been Removed Successfully!'), 'status');
    $response
      ->addCommand(new RedirectCommand(Url::fromRoute('miniorange_saml.customer_setup')
      ->toString()));
  }
  return $response;
}