3 namespace Drupal\{{ machine_name }}\Form;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Configure {{ name }} settings for this site.
11 class {{ class }} extends ConfigFormBase {
16 public function getFormId() {
17 return '{{ form_id }}';
23 protected function getEditableConfigNames() {
24 return ['{{ machine_name }}.settings'];
30 public function buildForm(array $form, FormStateInterface $form_state) {
32 '#type' => 'textfield',
33 '#title' => $this->t('Example'),
34 '#default_value' => $this->config('{{ machine_name }}.settings')->get('example'),
36 return parent::buildForm($form, $form_state);
42 public function validateForm(array &$form, FormStateInterface $form_state) {
43 if ($form_state->getValue('example') != 'example') {
44 $form_state->setErrorByName('example', $this->t('The value is not correct.'));
46 parent::validateForm($form, $form_state);
52 public function submitForm(array &$form, FormStateInterface $form_state) {
53 $this->config('{{ machine_name }}.settings')
54 ->set('example', $form_state->getValue('example'))
56 parent::submitForm($form, $form_state);