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