Pull merge.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / form / config.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Configure {{ name }} settings for this site.
10  */
11 class {{ class }} extends ConfigFormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return '{{ form_id }}';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function getEditableConfigNames() {
24     return ['{{ machine_name }}.settings'];
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildForm(array $form, FormStateInterface $form_state) {
31     $form['example'] = [
32       '#type' => 'textfield',
33       '#title' => $this->t('Example'),
34       '#default_value' => $this->config('{{ machine_name }}.settings')->get('example'),
35     ];
36     return parent::buildForm($form, $form_state);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
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.'));
45     }
46     parent::validateForm($form, $form_state);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function submitForm(array &$form, FormStateInterface $form_state) {
53     $this->config('{{ machine_name }}.settings')
54       ->set('example', $form_state->getValue('example'))
55       ->save();
56     parent::submitForm($form, $form_state);
57   }
58
59 }