public function OAuthKeyForm::submitForm in Lightning API 8
Same name and namespace in other branches
- 8.4 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::submitForm()
- 8.2 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::submitForm()
- 8.3 src/Form/OAuthKeyForm.php \Drupal\lightning_api\Form\OAuthKeyForm::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 ConfigFormBase::submitForm
File
- src/
Form/ OAuthKeyForm.php, line 172
Class
Namespace
Drupal\lightning_api\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$conf = [];
// Gather OpenSSL configuration values specified by the user.
$config = $form_state
->getValue('conf');
if ($config) {
$conf['config'] = $config;
}
try {
list($private_key, $public_key) = OAuthKey::generate($conf);
} catch (KeyGenerationException $e) {
return $this
->onException($e, $form_state);
}
$dir = rtrim($form_state
->getValue('dir'), '/');
$config = $this
->config('simple_oauth.settings');
try {
$destination = $dir . '/' . trim($form_state
->getValue('private_key'));
$destination = $this->key
->write($destination, $private_key);
$config
->set('private_key', $destination);
$destination = $dir . '/' . trim($form_state
->getValue('public_key'));
$destination = $this->key
->write($destination, $public_key);
$config
->set('public_key', $destination);
$config
->save();
} catch (\RuntimeException $e) {
return $this
->onException($e, $form_state);
}
drupal_set_message($this
->t('A key pair was generated successfully.'));
}