Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / form / config.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/form/config.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/form/config.twig
new file mode 100644 (file)
index 0000000..d093f1c
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Form;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Configure {{ name }} settings for this site.
+ */
+class {{ class }} extends ConfigFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return '{{ form_id }}';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return ['{{ machine_name }}.settings'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form['example'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Example'),
+      '#default_value' => $this->config('{{ machine_name }}.settings')->get('example'),
+    ];
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+    if ($form_state->getValue('example') != 'example') {
+      $form_state->setErrorByName('example', $this->t('The value is not correct.'));
+    }
+    parent::validateForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $this->config('{{ machine_name }}.settings')
+      ->set('example', $form_state->getValue('example'))
+      ->save();
+    parent::submitForm($form, $form_state);
+  }
+
+}