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

Test module.

File

core/modules/system/tests/modules/theme_test/theme_test.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test module.
  5. */
  6. use Drupal\Core\Extension\Extension;
  7. /**
  8. * Implements hook_theme().
  9. */
  10. function theme_test_theme($existing, $type, $theme, $path) {
  11. $items['theme_test'] = array(
  12. 'file' => 'theme_test.inc',
  13. 'variables' => array('foo' => ''),
  14. 'function' => 'theme_theme_test',
  15. );
  16. $items['theme_test_template_test'] = array(
  17. 'template' => 'theme_test.template_test',
  18. );
  19. $items['theme_test_template_test_2'] = array(
  20. 'template' => 'theme_test.template_test',
  21. );
  22. $items['theme_test_suggestion_provided'] = array(
  23. 'variables' => array(),
  24. );
  25. $items['theme_test_specific_suggestions'] = array(
  26. 'variables' => array(),
  27. );
  28. $items['theme_test_suggestions'] = array(
  29. 'variables' => array(),
  30. );
  31. $items['theme_test_general_suggestions'] = array(
  32. 'variables' => array(),
  33. );
  34. $items['theme_test_function_suggestions'] = array(
  35. 'variables' => array(),
  36. 'function' => 'theme_theme_test_function_suggestions',
  37. );
  38. $items['theme_test_suggestions_include'] = array(
  39. 'variables' => array(),
  40. 'function' => 'theme_theme_test_suggestions_include',
  41. );
  42. $items['theme_test_foo'] = array(
  43. 'variables' => array('foo' => NULL),
  44. 'function' => 'theme_theme_test_foo',
  45. );
  46. $items['theme_test_render_element'] = array(
  47. 'render element' => 'elements',
  48. );
  49. $items['theme_test_render_element_children'] = array(
  50. 'render element' => 'element',
  51. 'function' => 'theme_theme_test_render_element_children',
  52. );
  53. $items['theme_test_function_template_override'] = array(
  54. 'variables' => array(),
  55. 'function' => 'theme_theme_test_function_template_override',
  56. );
  57. $info['test_theme_not_existing_function'] = array(
  58. 'function' => 'test_theme_not_existing_function',
  59. );
  60. $items['theme_test_preprocess_suggestions'] = [
  61. 'variables' => [
  62. 'foo' => '',
  63. 'bar' => '',
  64. ],
  65. ];
  66. return $items;
  67. }
  68. /**
  69. * Implements hook_preprocess_HOOK() for HTML document templates.
  70. */
  71. function theme_test_preprocess_html(&$variables) {
  72. $variables['html_attributes']['theme_test_html_attribute'] = 'theme test html attribute value';
  73. $variables['attributes']['theme_test_body_attribute'] = 'theme test body attribute value';
  74. $variables['attributes']['theme_test_page_variable'] = 'Page variable is an array.';
  75. }
  76. /**
  77. * Implements hook_page_bottom().
  78. */
  79. function theme_test_page_bottom(array &$page_bottom) {
  80. $page_bottom['theme_test_page_bottom'] = array('#markup' => 'theme test page bottom markup');
  81. }
  82. /**
  83. * Implements template_preprocess_HOOK() for theme_test_function_suggestions theme functions.
  84. */
  85. function template_preprocess_theme_test_function_suggestions(&$variables) {
  86. }
  87. /**
  88. * Theme function for hook theme_test_foo.
  89. */
  90. function theme_theme_test_foo($variables) {
  91. return $variables['foo'];
  92. }
  93. /**
  94. * Theme function for hook theme_test_function_template_override.
  95. */
  96. function theme_theme_test_function_template_override($variables) {
  97. return 'theme_test_function_template_override test failed.';
  98. }
  99. /**
  100. * Implements hook_theme_suggestions_HOOK().
  101. */
  102. function theme_test_theme_suggestions_theme_test_preprocess_suggestions($variables) {
  103. return ['theme_test_preprocess_suggestions__' . $variables['foo']];
  104. }
  105. /**
  106. * Implements hook_preprocess_HOOK().
  107. */
  108. function theme_test_preprocess_theme_test_preprocess_suggestions(&$variables) {
  109. $variables['foo'] = 'Theme hook implementor=theme_theme_test_preprocess_suggestions().';
  110. }
  111. /**
  112. * Tests a module overriding a default hook with a suggestion.
  113. */
  114. function theme_test_preprocess_theme_test_preprocess_suggestions__monkey(&$variables) {
  115. $variables['foo'] = 'Monkey';
  116. }
  117. /**
  118. * Prepares variables for test render element templates.
  119. *
  120. * Default template: theme-test-render-element.html.twig.
  121. *
  122. * @param array $variables
  123. * An associative array containing:
  124. * - elements: An associative array containing the properties of the element.
  125. */
  126. function template_preprocess_theme_test_render_element(&$variables) {
  127. $variables['attributes']['data-variables-are-preprocessed'] = TRUE;
  128. }
  129. /**
  130. * Theme function for testing rendering of child elements via drupal_render().
  131. *
  132. * Theme hooks defining a 'render element' add an internal '#render_children'
  133. * property. When this property is found, drupal_render() avoids calling
  134. * the 'theme.manager' service 'render' method on the top-level element to
  135. * prevent infinite recursion.
  136. *
  137. * @param array $variables
  138. * An associative array containing:
  139. * - element: An associative array containing the properties of the element.
  140. */
  141. function theme_theme_test_render_element_children($variables) {
  142. return drupal_render($variables['element']);
  143. }
  144. /**
  145. * Returns HTML for a theme function suggestion test.
  146. */
  147. function theme_theme_test_function_suggestions($variables) {
  148. return 'Original theme function.';
  149. }
  150. /**
  151. * Implements hook_theme_suggestions_HOOK().
  152. */
  153. function theme_test_theme_suggestions_theme_test_suggestion_provided(array $variables) {
  154. return array('theme_test_suggestion_provided__' . 'foo');
  155. }
  156. /**
  157. * Implements hook_theme_suggestions_alter().
  158. */
  159. function theme_test_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  160. drupal_set_message(__FUNCTION__ . '() executed.');
  161. }
  162. /**
  163. * Implements hook_theme_suggestions_HOOK_alter().
  164. */
  165. function theme_test_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
  166. drupal_set_message(__FUNCTION__ . '() executed.');
  167. }
  168. /**
  169. * Returns HTML for a theme function include test.
  170. */
  171. function theme_theme_test_suggestions_include($variables) {
  172. return 'Original function before altering theme suggestions.';
  173. }
  174. /**
  175. * Implements hook_system_info_alter().
  176. *
  177. * @see \Drupal\system\Tests\Theme\ThemeInfoTest::testChanges()
  178. */
  179. function theme_test_system_info_alter(array &$info, Extension $file, $type) {
  180. if ($type == 'theme' && $file->getName() == 'test_theme' && \Drupal::state()->get('theme_test.modify_info_files')) {
  181. // Add a library to see if the system picks it up.
  182. $info += ['libraries' => []];
  183. $info['libraries'][] = 'core/backbone';
  184. }
  185. }
  186. /**
  187. * Implements hook_theme_suggestions_HOOK().
  188. */
  189. function theme_test_theme_suggestions_node(array $variables) {
  190. $xss = '<script type="text/javascript">alert(\'yo\');</script>';
  191. $suggestions[] = 'node__' . $xss;
  192. return $suggestions;
  193. }

Functions

Namesort descending Description
template_preprocess_theme_test_function_suggestions Implements template_preprocess_HOOK() for theme_test_function_suggestions theme functions.
template_preprocess_theme_test_render_element Prepares variables for test render element templates.
theme_test_page_bottom Implements hook_page_bottom().
theme_test_preprocess_html Implements hook_preprocess_HOOK() for HTML document templates.
theme_test_preprocess_theme_test_preprocess_suggestions Implements hook_preprocess_HOOK().
theme_test_preprocess_theme_test_preprocess_suggestions__monkey Tests a module overriding a default hook with a suggestion.
theme_test_system_info_alter Implements hook_system_info_alter().
theme_test_theme Implements hook_theme().
theme_test_theme_suggestions_alter Implements hook_theme_suggestions_alter().
theme_test_theme_suggestions_node Implements hook_theme_suggestions_HOOK().
theme_test_theme_suggestions_theme_test_preprocess_suggestions Implements hook_theme_suggestions_HOOK().
theme_test_theme_suggestions_theme_test_suggestions_alter Implements hook_theme_suggestions_HOOK_alter().
theme_test_theme_suggestions_theme_test_suggestion_provided Implements hook_theme_suggestions_HOOK().
theme_theme_test_foo Theme function for hook theme_test_foo.
theme_theme_test_function_suggestions Returns HTML for a theme function suggestion test.
theme_theme_test_function_template_override Theme function for hook theme_test_function_template_override.
theme_theme_test_render_element_children Theme function for testing rendering of child elements via drupal_render().
theme_theme_test_suggestions_include Returns HTML for a theme function include test.