542edc8a76f1ebc9ef668db82628949446c19178
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestMachineNameForm.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 'machine_name' elements.
11  */
12 class FormTestMachineNameForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'form_test_machine_name';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $form['machine_name_1_label'] = [
26       '#type' => 'textfield',
27       '#title' => 'Machine name 1 label',
28     ];
29     $form['machine_name_1'] = [
30       '#type' => 'machine_name',
31       '#title' => 'Machine name 1',
32       '#description' => 'A machine name.',
33       '#machine_name' => [
34         'source' => ['machine_name_1_label']
35       ],
36     ];
37     $form['machine_name_2_label'] = [
38       '#type' => 'textfield',
39       '#title' => 'Machine name 2 label',
40     ];
41     $form['machine_name_2'] = [
42       '#type' => 'machine_name',
43       '#title' => 'Machine name 2',
44       '#description' => 'Another machine name.',
45       '#machine_name' => [
46         'source' => ['machine_name_2_label']
47       ],
48     ];
49     $form['submit'] = [
50       '#type' => 'submit',
51       '#value' => 'Submit',
52     ];
53     return $form;
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function submitForm(array &$form, FormStateInterface $form_state) {
60     $form_state->setResponse(new JsonResponse($form_state->getValues()));
61   }
62
63 }