Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / form_test / form_test.module
1 <?php
2
3 /**
4  * @file
5  * Helper module for the form API tests.
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9
10 /**
11  * Implements hook_form_FORM_ID_alter() on behalf of block.module.
12  */
13 function block_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
14   \Drupal::messenger()->addStatus('block_form_form_test_alter_form_alter() executed.');
15 }
16
17 /**
18  * Implements hook_form_alter().
19  */
20 function form_test_form_alter(&$form, FormStateInterface $form_state, $form_id) {
21   if ($form_id == 'form_test_alter_form') {
22     \Drupal::messenger()->addStatus('form_test_form_alter() executed.');
23   }
24 }
25
26 /**
27  * Implements hook_form_FORM_ID_alter().
28  */
29 function form_test_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
30   \Drupal::messenger()->addStatus('form_test_form_form_test_alter_form_alter() executed.');
31 }
32
33 /**
34  * Implements hook_form_FORM_ID_alter() on behalf of system.module.
35  */
36 function system_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
37   \Drupal::messenger()->addStatus('system_form_form_test_alter_form_alter() executed.');
38 }
39
40 /**
41  * Create a header and options array. Helper function for callbacks.
42  */
43 function _form_test_tableselect_get_data() {
44   $header = [
45     'one' => t('One'),
46     'two' => t('Two'),
47     'three' => t('Three'),
48     'four' => t('Four'),
49   ];
50
51   $options['row1'] = [
52     'title' => ['data' => ['#title' => t('row1')]],
53     'one' => 'row1col1',
54     'two' => t('row1col2'),
55     'three' => t('row1col3'),
56     'four' => t('row1col4'),
57   ];
58
59   $options['row2'] = [
60     'title' => ['data' => ['#title' => t('row2')]],
61     'one' => 'row2col1',
62     'two' => t('row2col2'),
63     'three' => t('row2col3'),
64     'four' => t('row2col4'),
65   ];
66
67   $options['row3'] = [
68     'title' => ['data' => ['#title' => t('row3')]],
69     'one' => 'row3col1',
70     'two' => t('row3col2'),
71     'three' => t('row3col3'),
72     'four' => t('row3col4'),
73   ];
74
75   return [$header, $options];
76 }
77
78 /**
79  * Implements hook_form_FORM_ID_alter() for the registration form.
80  */
81 function form_test_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
82   $form['test_rebuild'] = [
83     '#type' => 'submit',
84     '#value' => t('Rebuild'),
85     '#submit' => ['form_test_user_register_form_rebuild'],
86   ];
87 }
88
89 /**
90  * Submit callback that just lets the form rebuild.
91  */
92 function form_test_user_register_form_rebuild($form, FormStateInterface $form_state) {
93   \Drupal::messenger()->addStatus('Form rebuilt.');
94   $form_state->setRebuild();
95 }
96
97 /**
98  * Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
99  */
100 function form_test_form_form_test_vertical_tabs_access_form_alter(&$form, &$form_state, $form_id) {
101   $form['vertical_tabs1']['#access'] = FALSE;
102   $form['vertical_tabs2']['#access'] = FALSE;
103   $form['tabs3']['#access'] = TRUE;
104   $form['fieldset1']['#access'] = FALSE;
105   $form['container']['#access'] = FALSE;
106 }
107
108 /**
109  * Ajax callback that returns the form element.
110  */
111 function form_test_tableselect_ajax_callback($form, FormStateInterface $form_state) {
112   return $form['tableselect'];
113 }