5 * Helper module for the form API tests.
8 use Drupal\Core\Form\FormStateInterface;
11 * Implements hook_form_FORM_ID_alter() on behalf of block.module.
13 function block_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
14 drupal_set_message('block_form_form_test_alter_form_alter() executed.');
18 * Implements hook_form_alter().
20 function form_test_form_alter(&$form, FormStateInterface $form_state, $form_id) {
21 if ($form_id == 'form_test_alter_form') {
22 drupal_set_message('form_test_form_alter() executed.');
27 * Implements hook_form_FORM_ID_alter().
29 function form_test_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
30 drupal_set_message('form_test_form_form_test_alter_form_alter() executed.');
34 * Implements hook_form_FORM_ID_alter() on behalf of system.module.
36 function system_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
37 drupal_set_message('system_form_form_test_alter_form_alter() executed.');
41 * Create a header and options array. Helper function for callbacks.
43 function _form_test_tableselect_get_data() {
47 'three' => t('Three'),
52 'title' => ['data' => ['#title' => t('row1')]],
54 'two' => t('row1col2'),
55 'three' => t('row1col3'),
56 'four' => t('row1col4'),
60 'title' => ['data' => ['#title' => t('row2')]],
62 'two' => t('row2col2'),
63 'three' => t('row2col3'),
64 'four' => t('row2col4'),
68 'title' => ['data' => ['#title' => t('row3')]],
70 'two' => t('row3col2'),
71 'three' => t('row3col3'),
72 'four' => t('row3col4'),
75 return [$header, $options];
79 * Implements hook_form_FORM_ID_alter() for the registration form.
81 function form_test_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
82 $form['test_rebuild'] = [
84 '#value' => t('Rebuild'),
85 '#submit' => ['form_test_user_register_form_rebuild'],
90 * Submit callback that just lets the form rebuild.
92 function form_test_user_register_form_rebuild($form, FormStateInterface $form_state) {
93 drupal_set_message('Form rebuilt.');
94 $form_state->setRebuild();
98 * Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
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;
109 * Ajax callback that returns the form element.
111 function form_test_tableselect_ajax_callback($form, FormStateInterface $form_state) {
112 return $form['tableselect'];