You are here

public function LockrRegisterForm::submitForm in Lockr 8.2

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

Class

LockrRegisterForm

Namespace

Drupal\lockr\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $email = $form_state
    ->getValue('email');
  $name = $this
    ->getSiteName();
  $site_client = $this->clientFactory
    ->getSiteClient();
  try {
    $site_client
      ->register($email, NULL, $name);
  } catch (LockrClientException $e) {
    if ($e->title === 'Missing header value' && $e->description === 'The Auth header is required.') {
      $form_state
        ->setRedirect('lockr.login');
      return;
    }
    elseif ($e->title === 'Partner mismatch') {
      $msg = "We didn't recognize your certificate, please ensure the provide path is a valid Lockr certificate.";
    }
    elseif ($e->title === 'Site exists') {
      $msg = 'This site is already registered. If you are experiencing issues, please contact support@lockr.io.';
    }
    else {
      $msg = 'An unknown error occurred, please try again later.';
    }
    drupal_set_message($msg, 'error');
    return;
  } catch (LockrServerException $e) {
    $msg = 'An unknown error occurred, please try again later.';
    drupal_set_message($msg, 'error');
    return;
  }
  drupal_set_message("That's it! You're signed up with Lockr; your keys are now safe.");
  $form_state
    ->setRedirect('entity.key.collection');
}