1. 8.3.x core/modules/system/tests/modules/form_test/form_test.module
  2. 8.0.x core/modules/system/tests/modules/form_test/form_test.module
  3. 8.1.x core/modules/system/tests/modules/form_test/form_test.module
  4. 8.2.x core/modules/system/tests/modules/form_test/form_test.module
  5. 8.4.x core/modules/system/tests/modules/form_test/form_test.module
  6. 7.x modules/simpletest/tests/form_test.module

Helper module for the form API tests.

File

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

Functions

Namesort descending Description
block_form_form_test_alter_form_alter Implements hook_form_FORM_ID_alter() on behalf of block.module.
form_test_form_alter Implements hook_form_alter().
form_test_form_form_test_alter_form_alter Implements hook_form_FORM_ID_alter().
form_test_form_form_test_vertical_tabs_access_form_alter Implements hook_form_FORM_ID_alter() for form_test_vertical_tabs_access_form().
form_test_form_user_register_form_alter Implements hook_form_FORM_ID_alter() for the registration form.
form_test_tableselect_ajax_callback Ajax callback that returns the form element.
form_test_user_register_form_rebuild Submit callback that just lets the form rebuild.
system_form_form_test_alter_form_alter Implements hook_form_FORM_ID_alter() on behalf of system.module.
_form_test_tableselect_get_data Create a header and options array. Helper function for callbacks.