theme_test.module

File

drupal-7.x/modules/simpletest/tests/theme_test.module
View source
  1. <?php
  2. /**
  3. * Implements hook_theme().
  4. */
  5. function theme_test_theme($existing, $type, $theme, $path) {
  6. $items['theme_test'] = array(
  7. 'file' => 'theme_test.inc',
  8. 'variables' => array('foo' => ''),
  9. );
  10. $items['theme_test_template_test'] = array(
  11. 'template' => 'theme_test.template_test',
  12. );
  13. $items['theme_test_template_test_2'] = array(
  14. 'template' => 'theme_test.template_test',
  15. );
  16. $items['theme_test_foo'] = array(
  17. 'variables' => array('foo' => NULL),
  18. );
  19. return $items;
  20. }
  21. /**
  22. * Implements hook_system_theme_info().
  23. */
  24. function theme_test_system_theme_info() {
  25. $themes['test_theme'] = drupal_get_path('module', 'theme_test') . '/themes/test_theme/test_theme.info';
  26. $themes['test_basetheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_basetheme/test_basetheme.info';
  27. $themes['test_subtheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_subtheme/test_subtheme.info';
  28. return $themes;
  29. }
  30. /**
  31. * Implements hook_menu().
  32. */
  33. function theme_test_menu() {
  34. $items['theme-test/suggestion'] = array(
  35. 'title' => 'Suggestion',
  36. 'page callback' => '_theme_test_suggestion',
  37. 'access arguments' => array('access content'),
  38. 'theme callback' => '_theme_custom_theme',
  39. 'type' => MENU_CALLBACK,
  40. );
  41. $items['theme-test/alter'] = array(
  42. 'title' => 'Suggestion',
  43. 'page callback' => '_theme_test_alter',
  44. 'access arguments' => array('access content'),
  45. 'theme callback' => '_theme_custom_theme',
  46. 'type' => MENU_CALLBACK,
  47. );
  48. $items['theme-test/hook-init'] = array(
  49. 'page callback' => 'theme_test_hook_init_page_callback',
  50. 'access callback' => TRUE,
  51. 'type' => MENU_CALLBACK,
  52. );
  53. return $items;
  54. }
  55. /**
  56. * Implements hook_init().
  57. */
  58. function theme_test_init() {
  59. if (arg(0) == 'theme-test' && arg(1) == 'hook-init') {
  60. // First, force the theme registry to be rebuilt on this page request. This
  61. // allows us to test a full initialization of the theme system in the code
  62. // below.
  63. drupal_theme_rebuild();
  64. // Next, initialize the theme system by storing themed text in a global
  65. // variable. We will use this later in theme_test_hook_init_page_callback()
  66. // to test that even when the theme system is initialized this early, it is
  67. // still capable of returning output and theming the page as a whole.
  68. $GLOBALS['theme_test_output'] = theme('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()'));
  69. }
  70. }
  71. /**
  72. * Implements hook_exit().
  73. */
  74. function theme_test_exit() {
  75. if (arg(0) == 'user') {
  76. // Register a fake registry loading callback. If it gets called by
  77. // theme_get_registry(), the registry has not been initialized yet.
  78. _theme_registry_callback('_theme_test_load_registry', array());
  79. print theme_get_registry() ? 'registry initialized' : 'registry not initialized';
  80. }
  81. }
  82. /**
  83. * Fake registry loading callback.
  84. */
  85. function _theme_test_load_registry() {
  86. return array();
  87. }
  88. /**
  89. * Menu callback for testing themed output generated in hook_init().
  90. */
  91. function theme_test_hook_init_page_callback() {
  92. return $GLOBALS['theme_test_output'];
  93. }
  94. /**
  95. * Custom theme callback.
  96. */
  97. function _theme_custom_theme() {
  98. return 'test_theme';
  99. }
  100. /**
  101. * Page callback, calls drupal_alter().
  102. *
  103. * This is for testing that the theme can have hook_*_alter() implementations
  104. * that run during page callback execution, even before theme() is called for
  105. * the first time.
  106. */
  107. function _theme_test_alter() {
  108. $data = 'foo';
  109. drupal_alter('theme_test_alter', $data);
  110. return "The altered data is $data.";
  111. }
  112. /**
  113. * Page callback, calls a theme hook suggestion.
  114. */
  115. function _theme_test_suggestion() {
  116. return theme(array('theme_test__suggestion', 'theme_test'), array());
  117. }
  118. /**
  119. * Theme function for testing theme('theme_test_foo').
  120. */
  121. function theme_theme_test_foo($variables) {
  122. return $variables['foo'];
  123. }