class LockrMigrateForm in Lockr 8.3
Same name and namespace in other branches
- 8.4 src/Form/LockrMigrateForm.php \Drupal\lockr\Form\LockrMigrateForm
- 8.2 src/Form/LockrMigrateForm.php \Drupal\lockr\Form\LockrMigrateForm
- 4.x src/Form/LockrMigrateForm.php \Drupal\lockr\Form\LockrMigrateForm
Form handler for Lockr move to production.
Hierarchy
- class \Drupal\lockr\Form\LockrMigrateForm implements ContainerInjectionInterface, FormInterface uses StringTranslationTrait
Expanded class hierarchy of LockrMigrateForm
1 file declares its use of LockrMigrateForm
- LockrAdminController.php in src/
Controller/ LockrAdminController.php
File
- src/
Form/ LockrMigrateForm.php, line 24
Namespace
Drupal\lockr\FormView source
class LockrMigrateForm implements ContainerInjectionInterface, FormInterface {
use StringTranslationTrait;
/**
* Simple config factory.
*
* @var ConfigFactoryInterface
*/
protected $configFactory;
/**
* Lockr library client.
*
* @var Lockr
*/
protected $lockr;
/**
* Constructs a new LockrMigrateForm.
*
* @param ConfigFactoryInterface $config_factory
* The simple config factory.
* @param Lockr $lockr
* The Lockr library client.
* @param TranslationInterface $translation
* The Drupal translator.
*/
public function __construct(ConfigFactoryInterface $config_factory, Lockr $lockr, TranslationInterface $translation) {
$this->configFactory = $config_factory;
$this->lockr = $lockr;
$this
->setStringTranslation($translation);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('lockr.lockr'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'lockr_migrate_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$build_info = $form_state
->getBuildInfo();
$info = $build_info['args'][0];
$form['instructions'] = [
'#preix' => '<p>',
'#markup' => $this
->t('Click the button below to deploy this site to production. This should only be done in your production environment as it writes a new certificate to the file system.'),
'#suffix' => '</p>',
];
$form['#attached']['library'][] = 'lockr/move_to_prod';
$form['#attached']['drupalSettings']['lockr'] = [
'accounts_host' => 'https://accounts.lockr.io',
'keyring_id' => $info['keyring']['id'],
];
$form['client_token'] = [
'#type' => 'hidden',
'#required' => TRUE,
];
$form['move_to_prod'] = [
'#type' => 'button',
'#value' => $this
->t('Migrate to Production'),
'#attributes' => [
'class' => [
'move-to-prod',
],
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#attributes' => [
'class' => [
'move-to-prod-submit',
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$client_token = $form_state
->getValue('client_token');
$dn = [
'countryName' => 'US',
'stateOrProvinceName' => 'Washington',
'localityName' => 'Tacoma',
'organizationName' => 'Lockr',
];
try {
$result = $this->lockr
->createCertClient($client_token, $dn);
CertWriter::writeCerts('prod', $result);
$config = $this->configFactory
->getEditable('lockr.settings');
$config
->set('custom', TRUE);
$config
->set('cert_path', 'private://lockr/prod/pair.pem');
$config
->save();
} catch (\Exception $e) {
// XXX: probably log and/or show message
throw $e;
return;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LockrMigrateForm:: |
protected | property | Simple config factory. | |
LockrMigrateForm:: |
protected | property | Lockr library client. | |
LockrMigrateForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LockrMigrateForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
LockrMigrateForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LockrMigrateForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LockrMigrateForm:: |
public | function |
Form validation handler. Overrides FormInterface:: |
|
LockrMigrateForm:: |
public | function | Constructs a new LockrMigrateForm. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |