423390d2225c08a855e392951fdf314a4b52fce7
[yaffs-website] / web / core / modules / system / tests / themes / test_theme / test_theme.theme
1 <?php
2
3 /**
4  * @file
5  * Theme to help test the Twig engine.
6  */
7
8 /**
9  * Implements THEME_preprocess_twig_theme_test_php_variables().
10  */
11 function test_theme_preprocess_twig_theme_test_php_variables(&$variables) {
12   $variables['php_values'] = _test_theme_twig_php_values();
13 }
14
15 /**
16  * Tests a theme overriding a suggestion of a base theme hook.
17  */
18 function test_theme_theme_test__suggestion($variables) {
19   return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
20 }
21
22 /**
23  * Implements hook_element_info_alter().
24  */
25 function test_theme_element_info_alter(&$info) {
26   // Decrease the default size of textfields.
27   if (isset($info['textfield']['#size'])) {
28     $info['textfield']['#size'] = 40;
29   }
30 }
31
32 /**
33  * Implements hook_library_info_alter().
34  */
35 function test_theme_library_info_alter(&$libraries, $extension) {
36   if ($extension === 'test_theme') {
37     $libraries['kitten']['js']['kittens.js'] = [];
38   }
39 }
40
41 /**
42  * Tests a theme implementing an alter hook.
43  *
44  * The confusing function name here is due to this being an implementation of
45  * the alter hook invoked when the 'theme_test' module calls
46  * \Drupal::moduleHandler->alter('theme_test_alter').
47  */
48 function test_theme_theme_test_alter_alter(&$data) {
49   $data = 'test_theme_theme_test_alter_alter was invoked';
50 }
51
52 /**
53  * Implements hook_theme_suggestions_alter().
54  */
55 function test_theme_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
56   \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
57   // Theme alter hooks run after module alter hooks, so add this theme
58   // suggestion to the beginning of the array so that the suggestion added by
59   // the theme_suggestions_test module can be picked up when that module is
60   // enabled.
61   if ($hook == 'theme_test_general_suggestions') {
62     array_unshift($suggestions, 'theme_test_general_suggestions__' . 'theme_override');
63   }
64 }
65
66 /**
67  * Implements hook_theme_suggestions_HOOK_alter().
68  */
69 function test_theme_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
70   \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
71   // Theme alter hooks run after module alter hooks, so add this theme
72   // suggestion to the beginning of the array so that the suggestion added by
73   // the theme_suggestions_test module can be picked up when that module is
74   // enabled.
75   array_unshift($suggestions, 'theme_test_suggestions__' . 'theme_override');
76 }
77
78 /**
79  * Implements hook_theme_suggestions_HOOK_alter().
80  */
81 function test_theme_theme_suggestions_theme_test_function_suggestions_alter(array &$suggestions, array $variables) {
82   // Theme alter hooks run after module alter hooks, so add this theme
83   // suggestion to the beginning of the array so that the suggestion added by
84   // the theme_suggestions_test module can be picked up when that module is
85   // enabled.
86   array_unshift($suggestions, 'theme_test_function_suggestions__' . 'theme_override');
87 }
88
89 /**
90  * Returns HTML for a theme function suggestion test.
91  *
92  * Implements the theme_test_function_suggestions__theme_override suggestion.
93  */
94 function test_theme_theme_test_function_suggestions__theme_override($variables) {
95   return 'Theme function overridden based on new theme suggestion provided by the test_theme theme.';
96 }
97
98 /**
99  * Returns HTML for a theme function suggestion test.
100  *
101  * Implements the theme_test_function_suggestions__module_override suggestion.
102  */
103 function test_theme_theme_test_function_suggestions__module_override($variables) {
104   return 'Theme function overridden based on new theme suggestion provided by a module.';
105 }
106
107 /**
108  * Implements hook_theme_registry_alter().
109  */
110 function test_theme_theme_registry_alter(&$registry) {
111   $registry['theme_test_template_test']['variables']['additional'] = 'value';
112 }
113
114 /**
115  * Tests a theme overriding a suggestion of a base theme hook.
116  */
117 function test_theme_theme_test_preprocess_suggestions__kitten__meerkat($variables) {
118   return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
119 }
120
121 /**
122  * Tests a theme overriding a default hook with a suggestion.
123  *
124  * Implements hook_preprocess_HOOK().
125  */
126 function test_theme_preprocess_theme_test_preprocess_suggestions(&$variables) {
127   $variables['foo'] = 'Theme hook implementor=test_theme_preprocess_theme_test_preprocess_suggestions().';
128 }
129
130 /**
131  * Tests a theme overriding a default hook with a suggestion.
132  */
133 function test_theme_preprocess_theme_test_preprocess_suggestions__suggestion(&$variables) {
134   $variables['foo'] = 'Suggestion';
135 }
136
137 /**
138  * Tests a theme overriding a default hook with a suggestion.
139  */
140 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten(&$variables) {
141   $variables['foo'] = 'Kitten';
142 }
143
144 /**
145  * Tests a theme overriding a default hook with a suggestion.
146  */
147 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__flamingo(&$variables) {
148   $variables['bar'] = 'Flamingo';
149 }
150
151 /**
152  * Tests a preprocess function with suggestions.
153  */
154 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose(&$variables) {
155   $variables['bar'] = 'Moose';
156 }