CamiSettingsForm.php in Custom Active Menu Item 8
File
src/Form/CamiSettingsForm.php
View source
<?php
namespace Drupal\cami\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CamiSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'cami_settings';
}
protected function getEditableConfigNames() {
return [
'cami.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('cami.settings');
$form['li_classes'] = array(
'#type' => 'textfield',
'#title' => t('List classes'),
'#description' => t('Classes applied to <strong>li</strong> element (separate classes with spaces)'),
'#default_value' => $config
->get('li_classes'),
);
$form['a_classes'] = array(
'#type' => 'textfield',
'#title' => t('Link classes'),
'#description' => t('Classes applied to <strong>a</strong> element (separate classes with spaces)'),
'#default_value' => $config
->get('a_classes'),
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('cami.settings')
->set('li_classes', $form_state
->getValue('li_classes'))
->set('a_classes', $form_state
->getValue('a_classes'))
->save();
parent::submitForm($form, $form_state);
}
}