Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestResponseForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Symfony\Component\HttpFoundation\JsonResponse;
8
9 /**
10  * Form constructor for testing #type 'url' elements.
11  *
12  * @internal
13  */
14 class FormTestResponseForm extends FormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'form_test_response';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function buildForm(array $form, FormStateInterface $form_state) {
27     $form['content'] = [
28       '#type' => 'textfield',
29       '#title' => 'Content',
30     ];
31     $form['status'] = [
32       '#type' => 'textfield',
33       '#title' => 'Status',
34       '#default_value' => 200,
35     ];
36     $form['submit'] = [
37       '#type' => 'submit',
38       '#value' => 'Submit',
39     ];
40     return $form;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function submitForm(array &$form, FormStateInterface $form_state) {
47     $values = $form_state->getValues();
48     $form_state->setResponse(new JsonResponse($values['content'], (int) $values['status']));
49   }
50
51 }