You are here

public function LockrRegisterForm::submitForm in Lockr 4.x

Same name and namespace in other branches
  1. 8.4 src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm::submitForm()
  2. 8.2 src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm::submitForm()
  3. 8.3 src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm::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 FormInterface::submitForm

File

src/Form/LockrRegisterForm.php, line 146

Class

LockrRegisterForm
Form handler for Lockr registration.

Namespace

Drupal\lockr\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $client_token = $form_state
    ->getValue('client_token');
  $partner = $this->settingsFactory
    ->getPartner();
  try {
    if (is_null($partner)) {
      $dn = [
        'countryName' => 'US',
        'stateOrProvinceName' => 'Washington',
        'localityName' => 'Tacoma',
        'organizationName' => 'Lockr',
      ];
      $result = $this->lockr
        ->createCertClient($client_token, $dn);
      CertWriter::writeCerts('dev', $result);
      $config = $this->configFactory
        ->getEditable('lockr.settings');
      $config
        ->set('custom', TRUE);
      $config
        ->set('cert_path', 'private://lockr/dev/pair.pem');
      $config
        ->save();
    }
    elseif ($partner['name'] === 'pantheon') {
      $this->lockr
        ->createPantheonClient($client_token);
    }
  } catch (\Exception $e) {

    // XXX: probably log and/or show message
    throw $e;
    return;
  }
  $this->messenger
    ->addMessage($this
    ->t("That's it! You're signed up with Lockr; your keys are now safe."));
  $form_state
    ->setRedirect('entity.key.collection');
}