SettingsForm.php in Sidr: Accessible Mobile Menus 8
File
src/Form/SettingsForm.php
View source
<?php
namespace Drupal\sidr\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SettingsForm extends ConfigFormBase {
public function getFormId() {
return 'sidr_settings';
}
protected function getEditableConfigNames() {
return [
'sidr.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('sidr.settings');
$form['sidr_theme'] = [
'#type' => 'select',
'#title' => $this
->t('Sidr theme'),
'#description' => $this
->t('If you want to style Sidr with your own CSS, choose %bare', [
'%bare' => $this
->t('Bare'),
]),
'#default_value' => $config
->get('sidr_theme') ?: 'bare',
'#options' => [
'bare' => $this
->t('Bare'),
'light' => $this
->t('Light'),
'dark' => $this
->t('Dark'),
],
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$keys = [
'sidr_theme',
];
$config = $this
->config('sidr.settings');
foreach ($keys as $key) {
$config
->set($key, $form_state
->getValue($key));
}
$config
->save();
parent::submitForm($form, $form_state);
}
}