theme_test.module

  1. drupal
    1. 7 modules/simpletest/tests/theme_test.module
    2. 8 core/modules/system/tests/modules/theme_test/theme_test.module

Functions & methods

NameDescription
theme_test_exitImplements hook_exit().
theme_test_hook_init_page_callbackMenu callback for testing themed output generated in hook_init().
theme_test_initImplements hook_init().
theme_test_menuImplements hook_menu().
theme_test_system_theme_infoImplements hook_system_theme_info().
theme_test_themeImplements hook_theme().
theme_theme_test_fooTheme function for testing theme('theme_test_foo').
_theme_custom_themeCustom theme callback.
_theme_test_alterPage callback, calls drupal_alter().
_theme_test_load_registryFake registry loading callback.
_theme_test_suggestionPage callback, calls a theme hook suggestion.

File

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