Version 1
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / FormTestArgumentsObject.php
1 <?php
2
3 namespace Drupal\form_test;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a test form object that needs arguments.
10  */
11 class FormTestArgumentsObject extends ConfigFormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'form_test_form_test_arguments_object';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function getEditableConfigNames() {
24     return ['form_test.object'];
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildForm(array $form, FormStateInterface $form_state, $arg = NULL) {
31     $form['element'] = ['#markup' => 'The FormTestArgumentsObject::buildForm() method was used for this form.'];
32
33     $form['bananas'] = [
34       '#type' => 'textfield',
35       '#default_value' => $arg,
36       '#title' => $this->t('Bananas'),
37     ];
38
39     $form['actions']['#type'] = 'actions';
40     $form['actions']['submit'] = [
41       '#type' => 'submit',
42       '#value' => $this->t('Save'),
43     ];
44     return $form;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function validateForm(array &$form, FormStateInterface $form_state) {
51     drupal_set_message($this->t('The FormTestArgumentsObject::validateForm() method was used for this form.'));
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function submitForm(array &$form, FormStateInterface $form_state) {
58     drupal_set_message($this->t('The FormTestArgumentsObject::submitForm() method was used for this form.'));
59     $this->config('form_test.object')
60       ->set('bananas', $form_state->getValue('bananas'))
61       ->save();
62   }
63
64 }