AccessTokenSettingsForm.php in Simple OAuth (OAuth2) & OpenID Connect 8
File
src/Entity/Form/AccessTokenSettingsForm.php
View source
<?php
namespace Drupal\simple_oauth\Entity\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class AccessTokenSettingsForm extends FormBase {
public function getFormId() {
return 'access_token_settings';
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$save = FALSE;
$settings = $this
->configFactory()
->getEditable('simple_oauth.settings');
if ($expiration = $form_state
->getValue('expiration')) {
$settings
->set('expiration', $expiration);
$save = TRUE;
}
if ($refresh_extension = $form_state
->getValue('refresh_extension')) {
$settings
->set('refresh_extension', $refresh_extension);
$save = TRUE;
}
if ($save) {
$settings
->save();
}
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['expiration'] = [
'#type' => 'number',
'#title' => $this
->t('Expiration time'),
'#description' => $this
->t('The default value, in seconds, to be used as expiration time when creating new tokens. This value may be overridden in the token generation form.'),
'#default_value' => $this
->config('simple_oauth.settings')
->get('expiration'),
];
$form['refresh_extension'] = [
'#type' => 'number',
'#title' => $this
->t('Refresh extension'),
'#description' => $this
->t('The time a refresh token stays valid after the access token has expired.'),
'#default_value' => $this
->config('simple_oauth.settings')
->get('refresh_extension'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}
}