Version 1
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / FormTestObject.php
diff --git a/web/core/modules/system/tests/modules/form_test/src/FormTestObject.php b/web/core/modules/system/tests/modules/form_test/src/FormTestObject.php
new file mode 100644 (file)
index 0000000..f99fbe7
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace Drupal\form_test;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Provides a test form object.
+ */
+class FormTestObject extends ConfigFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'form_test_form_test_object';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return ['form_test.object'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form['element'] = ['#markup' => 'The FormTestObject::buildForm() method was used for this form.'];
+
+    $form['bananas'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Bananas'),
+    ];
+    $form['strawberry'] = [
+      '#type' => 'hidden',
+      '#value' => 'red',
+      '#attributes' => ['id' => 'redstrawberryhiddenfield'],
+    ];
+
+    $form['actions']['#type'] = 'actions';
+    $form['actions']['submit'] = [
+      '#type' => 'submit',
+      '#value' => $this->t('Save'),
+    ];
+
+    $form['#title'] = 'Test dynamic title';
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+    drupal_set_message($this->t('The FormTestObject::validateForm() method was used for this form.'));
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    drupal_set_message($this->t('The FormTestObject::submitForm() method was used for this form.'));
+    $this->config('form_test.object')
+      ->set('bananas', $form_state->getValue('bananas'))
+      ->save();
+  }
+
+}