037505637dd0be0b4efd653f226c85d9d8610d43
[yaffs-website] / web / modules / contrib / ctools / tests / modules / ctools_wizard_test / src / Form / OneForm.php
1 <?php
2
3 namespace Drupal\ctools_wizard_test\Form;
4
5
6 use Drupal\Core\Form\FormBase;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Simple wizard step form.
11  */
12 class OneForm extends FormBase {
13
14   /**
15    * Returns a unique string identifying the form.
16    *
17    * @return string
18    *   The unique string identifying the form.
19    */
20   public function getFormId() {
21     return 'ctools_wizard_test_one_form';
22   }
23
24   /**
25    * Form constructor.
26    *
27    * @param array $form
28    *   An associative array containing the structure of the form.
29    * @param \Drupal\Core\Form\FormStateInterface $form_state
30    *   The current state of the form.
31    *
32    * @return array
33    *   The form structure.
34    */
35   public function buildForm(array $form, FormStateInterface $form_state) {
36     $cached_values = $form_state->getTemporaryValue('wizard');
37     $form['one'] = [
38       '#title' => $this->t('One'),
39       '#type' => 'textfield',
40       '#default_value' => !empty($cached_values['one']) ? $cached_values['one'] : '',
41     ];
42     $form['dynamic'] = [
43       '#title' => $this->t('Dynamic value'),
44       '#type' => 'item',
45       '#markup' => !empty($cached_values['dynamic']) ? $cached_values['dynamic'] : '',
46     ];
47     return $form;
48   }
49
50   /**
51    * Form submission handler.
52    *
53    * @param array $form
54    *   An associative array containing the structure of the form.
55    * @param \Drupal\Core\Form\FormStateInterface $form_state
56    *   The current state of the form.
57    */
58   public function submitForm(array &$form, FormStateInterface $form_state) {
59     $keys = array(
60       'one',
61     );
62     $cached_values = $form_state->getTemporaryValue('wizard');
63     foreach ($keys as $key) {
64       $cached_values[$key] = $form_state->getValue($key);
65     }
66     $form_state->setTemporaryValue('wizard', $cached_values);
67
68     drupal_set_message($this->t('Dynamic value submitted: @value', ['@value' => $cached_values['dynamic']]));;
69   }
70
71 }