3 namespace Drupal\form_test;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides a test form object.
11 class FormTestObject extends ConfigFormBase {
16 public function getFormId() {
17 return 'form_test_form_test_object';
23 protected function getEditableConfigNames() {
24 return ['form_test.object'];
30 public function buildForm(array $form, FormStateInterface $form_state) {
31 $form['element'] = ['#markup' => 'The FormTestObject::buildForm() method was used for this form.'];
34 '#type' => 'textfield',
35 '#title' => $this->t('Bananas'),
37 $form['strawberry'] = [
40 '#attributes' => ['id' => 'redstrawberryhiddenfield'],
43 $form['actions']['#type'] = 'actions';
44 $form['actions']['submit'] = [
46 '#value' => $this->t('Save'),
49 $form['#title'] = 'Test dynamic title';
57 public function validateForm(array &$form, FormStateInterface $form_state) {
58 drupal_set_message($this->t('The FormTestObject::validateForm() method was used for this form.'));
64 public function submitForm(array &$form, FormStateInterface $form_state) {
65 drupal_set_message($this->t('The FormTestObject::submitForm() method was used for this form.'));
66 $this->config('form_test.object')
67 ->set('bananas', $form_state->getValue('bananas'))