Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / modules / ajax_forms_test / src / Form / AjaxFormsTestCommandsForm.php
1 <?php
2
3 namespace Drupal\ajax_forms_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form constructor for the Ajax Command display form.
10  *
11  * @internal
12  */
13 class AjaxFormsTestCommandsForm extends FormBase {
14
15   /**
16    * {@inheritdoc}.
17    */
18   public function getFormId() {
19     return 'ajax_forms_test_ajax_commands_form';
20   }
21
22   /**
23    * {@inheritdoc}.
24    */
25   public function buildForm(array $form, FormStateInterface $form_state) {
26     $form = [];
27
28     // Shows the 'after' command with a callback generating commands.
29     $form['after_command_example'] = [
30       '#value' => $this->t("AJAX 'After': Click to put something after the div"),
31       '#type' => 'submit',
32       '#ajax' => [
33         'callback' => 'ajax_forms_test_advanced_commands_after_callback',
34       ],
35       '#suffix' => '<div id="after_div">Something can be inserted after this</div>',
36     ];
37
38     // Shows the 'alert' command.
39     $form['alert_command_example'] = [
40       '#value' => $this->t("AJAX 'Alert': Click to alert"),
41       '#type' => 'submit',
42       '#ajax' => [
43         'callback' => 'ajax_forms_test_advanced_commands_alert_callback',
44       ],
45     ];
46
47     // Shows the 'append' command.
48     $form['append_command_example'] = [
49       '#value' => $this->t("AJAX 'Append': Click to append something"),
50       '#type' => 'submit',
51       '#ajax' => [
52         'callback' => 'ajax_forms_test_advanced_commands_append_callback',
53       ],
54       '#suffix' => '<div id="append_div">Append inside this div</div>',
55     ];
56
57     // Shows the 'before' command.
58     $form['before_command_example'] = [
59       '#value' => $this->t("AJAX 'before': Click to put something before the div"),
60       '#type' => 'submit',
61       '#ajax' => [
62         'callback' => 'ajax_forms_test_advanced_commands_before_callback',
63       ],
64       '#suffix' => '<div id="before_div">Insert something before this.</div>',
65     ];
66
67     // Shows the 'changed' command without asterisk.
68     $form['changed_command_example'] = [
69       '#value' => $this->t("AJAX changed: Click to mark div changed."),
70       '#type' => 'submit',
71       '#ajax' => [
72         'callback' => 'ajax_forms_test_advanced_commands_changed_callback',
73       ],
74       '#suffix' => '<div id="changed_div"> <div id="changed_div_mark_this">This div can be marked as changed or not.</div></div>',
75     ];
76     // Shows the 'changed' command adding the asterisk.
77     $form['changed_command_asterisk_example'] = [
78       '#value' => $this->t("AJAX changed: Click to mark div changed with asterisk."),
79       '#type' => 'submit',
80       '#ajax' => [
81         'callback' => 'ajax_forms_test_advanced_commands_changed_asterisk_callback',
82       ],
83     ];
84
85     // Shows the Ajax 'css' command.
86     $form['css_command_example'] = [
87       '#value' => $this->t("Set the '#box' div to be blue."),
88       '#type' => 'submit',
89       '#ajax' => [
90         'callback' => 'ajax_forms_test_advanced_commands_css_callback',
91       ],
92       '#suffix' => '<div id="css_div" style="height: 50px; width: 50px; border: 1px solid black"> box</div>',
93     ];
94
95     // Shows the Ajax 'data' command. But there is no use of this information,
96     // as this would require a javascript client to use the data.
97     $form['data_command_example'] = [
98       '#value' => $this->t("AJAX data command: Issue command."),
99       '#type' => 'submit',
100       '#ajax' => [
101         'callback' => 'ajax_forms_test_advanced_commands_data_callback',
102       ],
103       '#suffix' => '<div id="data_div">Data attached to this div.</div>',
104     ];
105
106     // Shows the Ajax 'invoke' command.
107     $form['invoke_command_example'] = [
108       '#value' => $this->t("AJAX invoke command: Invoke addClass() method."),
109       '#type' => 'submit',
110       '#ajax' => [
111         'callback' => 'ajax_forms_test_advanced_commands_invoke_callback',
112       ],
113       '#suffix' => '<div id="invoke_div">Original contents</div>',
114     ];
115
116     // Shows the Ajax 'html' command.
117     $form['html_command_example'] = [
118       '#value' => $this->t("AJAX html: Replace the HTML in a selector."),
119       '#type' => 'submit',
120       '#ajax' => [
121         'callback' => 'ajax_forms_test_advanced_commands_html_callback',
122       ],
123       '#suffix' => '<div id="html_div">Original contents</div>',
124     ];
125
126     // Shows the Ajax 'insert' command.
127     $form['insert_command_example'] = [
128       '#value' => $this->t("AJAX insert: Let client insert based on #ajax['method']."),
129       '#type' => 'submit',
130       '#ajax' => [
131         'callback' => 'ajax_forms_test_advanced_commands_insert_callback',
132         'method' => 'prepend',
133       ],
134       '#suffix' => '<div id="insert_div">Original contents</div>',
135     ];
136
137     // Shows the Ajax 'prepend' command.
138     $form['prepend_command_example'] = [
139       '#value' => $this->t("AJAX 'prepend': Click to prepend something"),
140       '#type' => 'submit',
141       '#ajax' => [
142         'callback' => 'ajax_forms_test_advanced_commands_prepend_callback',
143       ],
144       '#suffix' => '<div id="prepend_div">Something will be prepended to this div. </div>',
145     ];
146
147     // Shows the Ajax 'remove' command.
148     $form['remove_command_example'] = [
149       '#value' => $this->t("AJAX 'remove': Click to remove text"),
150       '#type' => 'submit',
151       '#ajax' => [
152         'callback' => 'ajax_forms_test_advanced_commands_remove_callback',
153       ],
154       '#suffix' => '<div id="remove_div"><div id="remove_text">text to be removed</div></div>',
155     ];
156
157     // Shows the Ajax 'restripe' command.
158     $form['restripe_command_example'] = [
159       '#type' => 'submit',
160       '#value' => $this->t("AJAX 'restripe' command"),
161       '#ajax' => [
162         'callback' => 'ajax_forms_test_advanced_commands_restripe_callback',
163       ],
164       '#suffix' => '<div id="restripe_div">
165                     <table id="restripe_table" style="border: 1px solid black" >
166                     <tr id="table-first"><td>first row</td></tr>
167                     <tr ><td>second row</td></tr>
168                     </table>
169                     </div>',
170     ];
171
172     // Demonstrates the Ajax 'settings' command. The 'settings' command has
173     // nothing visual to "show", but it can be tested via SimpleTest and via
174     // Firebug.
175     $form['settings_command_example'] = [
176       '#type' => 'submit',
177       '#value' => $this->t("AJAX 'settings' command"),
178       '#ajax' => [
179         'callback' => 'ajax_forms_test_advanced_commands_settings_callback',
180       ],
181     ];
182
183     // Shows the Ajax 'add_css' command.
184     $form['add_css_command_example'] = [
185       '#type' => 'submit',
186       '#value' => $this->t("AJAX 'add_css' command"),
187       '#ajax' => [
188         'callback' => 'ajax_forms_test_advanced_commands_add_css_callback',
189       ],
190     ];
191
192     $form['submit'] = [
193       '#type' => 'submit',
194       '#value' => $this->t('Submit'),
195     ];
196
197     return $form;
198   }
199
200   /**
201    * {@inheritdoc}.
202    */
203   public function submitForm(array &$form, FormStateInterface $form_state) {
204   }
205
206 }