SettingsForm.php in Moderation Dashboard 8
File
src/Form/SettingsForm.php
View source
<?php
namespace Drupal\moderation_dashboard\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SettingsForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'moderation_dashboard.settings',
];
}
public function getFormId() {
return 'moderation_dashboard_settings_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('moderation_dashboard.settings');
$form['redirect_on_login'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Redirect on login'),
'#default_value' => $config
->get('redirect_on_login'),
'#description' => $this
->t('Redirect to moderation dashboard after login.'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('moderation_dashboard.settings')
->set('redirect_on_login', $values['redirect_on_login'])
->save();
parent::submitForm($form, $form_state);
}
}