class LockrRegisterForm in Lockr 8.2
Same name and namespace in other branches
- 8.4 src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm
- 8.3 src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm
- 4.x src/Form/LockrRegisterForm.php \Drupal\lockr\Form\LockrRegisterForm
Hierarchy
- class \Drupal\lockr\Form\LockrRegisterForm implements ContainerInjectionInterface, FormInterface
Expanded class hierarchy of LockrRegisterForm
1 file declares its use of LockrRegisterForm
- LockrAdminController.php in src/
Controller/ LockrAdminController.php
File
- src/
Form/ LockrRegisterForm.php, line 18
Namespace
Drupal\lockr\FormView source
class LockrRegisterForm implements ContainerInjectionInterface, FormInterface {
/** @var ClientFactory */
protected $clientFactory;
/** @var EmailValidator */
protected $emailValidator;
/** @var ConfigFactoryInterface */
protected $configFactory;
public function __construct(ClientFactory $client_factory, EmailValidator $email_validator, ConfigFactoryInterface $config_factory) {
$this->clientFactory = $client_factory;
$this->emailValidator = $email_validator;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('lockr.client_factory'), $container
->get('email.validator'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'lockr_register_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['email'] = [
'#type' => 'textfield',
'#title' => 'Email address',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Sign up',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$email = $form_state
->getValue('email');
if (!$this->emailValidator
->isValid($email)) {
$form_state
->setErrorByName('email', 'Please enter a valid email address.');
}
}
/**
* {@inheritdoc}
*/
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');
}
/**
* Get the human readable name of the site.
*/
protected function getSiteName() {
return $this->configFactory
->get('system.site')
->get('name');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LockrRegisterForm:: |
protected | property | @var ClientFactory | |
LockrRegisterForm:: |
protected | property | @var ConfigFactoryInterface | |
LockrRegisterForm:: |
protected | property | @var EmailValidator | |
LockrRegisterForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LockrRegisterForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
LockrRegisterForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LockrRegisterForm:: |
protected | function | Get the human readable name of the site. | |
LockrRegisterForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LockrRegisterForm:: |
public | function |
Form validation handler. Overrides FormInterface:: |
|
LockrRegisterForm:: |
public | function |