module_test.module 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function module_test_permission() {
  6. return array(
  7. 'module_test perm' => t('example perm for module_test module'),
  8. );
  9. }
  10. /**
  11. * Implements hook_system_info_alter().
  12. *
  13. * Manipulate module dependencies to test dependency chains.
  14. */
  15. function module_test_system_info_alter(&$info, $file, $type) {
  16. if (variable_get('dependency_test', FALSE) == 'missing dependency') {
  17. if ($file->name == 'forum') {
  18. // Make forum module depend on poll.
  19. $info['dependencies'][] = 'poll';
  20. }
  21. elseif ($file->name == 'poll') {
  22. // Make poll depend on a made-up module.
  23. $info['dependencies'][] = 'foo';
  24. }
  25. }
  26. elseif (variable_get('dependency_test', FALSE) == 'dependency') {
  27. if ($file->name == 'forum') {
  28. // Make the forum module depend on poll.
  29. $info['dependencies'][] = 'poll';
  30. }
  31. elseif ($file->name == 'poll') {
  32. // Make poll depend on php module.
  33. $info['dependencies'][] = 'php';
  34. }
  35. }
  36. elseif (variable_get('dependency_test', FALSE) == 'version dependency') {
  37. if ($file->name == 'forum') {
  38. // Make the forum module depend on poll.
  39. $info['dependencies'][] = 'poll';
  40. }
  41. elseif ($file->name == 'poll') {
  42. // Make poll depend on a specific version of php module.
  43. $info['dependencies'][] = 'php (1.x)';
  44. }
  45. elseif ($file->name == 'php') {
  46. // Set php module to a version compatible with the above.
  47. $info['version'] = '7.x-1.0';
  48. }
  49. }
  50. if ($file->name == 'seven' && $type == 'theme') {
  51. $info['regions']['test_region'] = t('Test region');
  52. }
  53. }
  54. /**
  55. * Implements hook_hook_info().
  56. */
  57. function module_test_hook_info() {
  58. $hooks['test_hook'] = array(
  59. 'group' => 'file',
  60. );
  61. return $hooks;
  62. }
  63. /**
  64. * Implements hook_menu().
  65. */
  66. function module_test_menu() {
  67. $items['module-test/hook-dynamic-loading-invoke'] = array(
  68. 'title' => 'Test hook dynamic loading (invoke)',
  69. 'page callback' => 'module_test_hook_dynamic_loading_invoke',
  70. 'access arguments' => array('access content'),
  71. );
  72. $items['module-test/hook-dynamic-loading-invoke-all'] = array(
  73. 'title' => 'Test hook dynamic loading (invoke_all)',
  74. 'page callback' => 'module_test_hook_dynamic_loading_invoke_all',
  75. 'access arguments' => array('access content'),
  76. );
  77. return $items;
  78. }
  79. /**
  80. * Page callback for 'hook dynamic loading' test.
  81. *
  82. * If the hook is dynamically loaded correctly, the menu callback should
  83. * return 'success!'.
  84. */
  85. function module_test_hook_dynamic_loading_invoke() {
  86. $result = module_invoke('module_test', 'test_hook');
  87. return $result['module_test'];
  88. }
  89. /**
  90. * Page callback for 'hook dynamic loading' test.
  91. *
  92. * If the hook is dynamically loaded correctly, the menu callback should
  93. * return 'success!'.
  94. */
  95. function module_test_hook_dynamic_loading_invoke_all() {
  96. $result = module_invoke_all('test_hook');
  97. return $result['module_test'];
  98. }
  99. /**
  100. * Implements hook_modules_enabled().
  101. */
  102. function module_test_modules_enabled($modules) {
  103. // Record the ordered list of modules that were passed in to this hook so we
  104. // can check that the modules were enabled in the correct sequence.
  105. variable_set('test_module_enable_order', $modules);
  106. }
  107. /**
  108. * Implements hook_modules_disabled().
  109. */
  110. function module_test_modules_disabled($modules) {
  111. // Record the ordered list of modules that were passed in to this hook so we
  112. // can check that the modules were disabled in the correct sequence.
  113. variable_set('test_module_disable_order', $modules);
  114. }
  115. /**
  116. * Implements hook_modules_uninstalled().
  117. */
  118. function module_test_modules_uninstalled($modules) {
  119. // Record the ordered list of modules that were passed in to this hook so we
  120. // can check that the modules were uninstalled in the correct sequence.
  121. variable_set('test_module_uninstall_order', $modules);
  122. }
  123. /**
  124. * Implements hook_module_implements_alter()
  125. */
  126. function module_test_module_implements_alter(&$implementations, $hook) {
  127. if ($hook === 'altered_test_hook') {
  128. // Add a hook implementation, that will be found in
  129. // module_test.implementations.inc.
  130. $implementations['module_test'] = 'implementations';
  131. }
  132. }