/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { list($exists, $_) = Lockr::site()->exists(); if (!$exists) { $form['need_register'] = ['#prefix' => '<p>', '#markup' => $this->t('This site has not yet registered with Lockr, ' . 'please <a href="@link">click here to register</a>.', ['@link' => Url::fromRoute('lockr.register')->toString()]), '#suffix' => '</p>']; } return $form; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $email = $form_state->getValue('email'); $pass = $form_state->getValue('pass'); $name = \Drupal::config('system.site')->get('name'); try { Lockr::site()->register($email, $pass, $name); } catch (ClientException $e) { drupal_set_message($this->t('Login credentials incorrect, please try again.'), 'error'); return; } catch (ServerException $e) { drupal_set_message($this->t('An unknown error has occurred, please try again later.'), 'error'); return; } drupal_set_message($this->t("That's it! You're signed up with Lockr; your keys are now safe.")); $form_state->setRedirect($form_state->get('destination')); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $email = $form_state->getValue('email'); $destination = $form_state->get('destination'); $name = \Drupal::config('system.site')->get('name'); try { Lockr::site()->register($email, null, $name); } catch (ClientException $e) { drupal_set_message($this->t('This email is already registered with Lockr. ' . 'Please login to register a new site.')); $form_state->setRedirect('lockr.login', [], ['query' => ['email' => $email, 'destination' => $destination]]); return; } catch (ServerException $e) { $form_state->setErrorByName('', $this->t('An unknown error has occurred, please try again later.')); return; } drupal_set_message($this->t("That's it! You're signed up with Lockr; your keys are now safe.")); $form_state->setRedirect($destination); }