summaryrefslogtreecommitdiffstats
path: root/core/modules/system/tests/themes/test_theme/test_theme.theme
blob: 423390d2225c08a855e392951fdf314a4b52fce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php

/**
 * @file
 * Theme to help test the Twig engine.
 */

/**
 * Implements THEME_preprocess_twig_theme_test_php_variables().
 */
function test_theme_preprocess_twig_theme_test_php_variables(&$variables) {
  $variables['php_values'] = _test_theme_twig_php_values();
}

/**
 * Tests a theme overriding a suggestion of a base theme hook.
 */
function test_theme_theme_test__suggestion($variables) {
  return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
}

/**
 * Implements hook_element_info_alter().
 */
function test_theme_element_info_alter(&$info) {
  // Decrease the default size of textfields.
  if (isset($info['textfield']['#size'])) {
    $info['textfield']['#size'] = 40;
  }
}

/**
 * Implements hook_library_info_alter().
 */
function test_theme_library_info_alter(&$libraries, $extension) {
  if ($extension === 'test_theme') {
    $libraries['kitten']['js']['kittens.js'] = [];
  }
}

/**
 * Tests a theme implementing an alter hook.
 *
 * The confusing function name here is due to this being an implementation of
 * the alter hook invoked when the 'theme_test' module calls
 * \Drupal::moduleHandler->alter('theme_test_alter').
 */
function test_theme_theme_test_alter_alter(&$data) {
  $data = 'test_theme_theme_test_alter_alter was invoked';
}

/**
 * Implements hook_theme_suggestions_alter().
 */
function test_theme_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
  // Theme alter hooks run after module alter hooks, so add this theme
  // suggestion to the beginning of the array so that the suggestion added by
  // the theme_suggestions_test module can be picked up when that module is
  // enabled.
  if ($hook == 'theme_test_general_suggestions') {
    array_unshift($suggestions, 'theme_test_general_suggestions__' . 'theme_override');
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function test_theme_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
  \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
  // Theme alter hooks run after module alter hooks, so add this theme
  // suggestion to the beginning of the array so that the suggestion added by
  // the theme_suggestions_test module can be picked up when that module is
  // enabled.
  array_unshift($suggestions, 'theme_test_suggestions__' . 'theme_override');
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function test_theme_theme_suggestions_theme_test_function_suggestions_alter(array &$suggestions, array $variables) {
  // Theme alter hooks run after module alter hooks, so add this theme
  // suggestion to the beginning of the array so that the suggestion added by
  // the theme_suggestions_test module can be picked up when that module is
  // enabled.
  array_unshift($suggestions, 'theme_test_function_suggestions__' . 'theme_override');
}

/**
 * Returns HTML for a theme function suggestion test.
 *
 * Implements the theme_test_function_suggestions__theme_override suggestion.
 */
function test_theme_theme_test_function_suggestions__theme_override($variables) {
  return 'Theme function overridden based on new theme suggestion provided by the test_theme theme.';
}

/**
 * Returns HTML for a theme function suggestion test.
 *
 * Implements the theme_test_function_suggestions__module_override suggestion.
 */
function test_theme_theme_test_function_suggestions__module_override($variables) {
  return 'Theme function overridden based on new theme suggestion provided by a module.';
}

/**
 * Implements hook_theme_registry_alter().
 */
function test_theme_theme_registry_alter(&$registry) {
  $registry['theme_test_template_test']['variables']['additional'] = 'value';
}

/**
 * Tests a theme overriding a suggestion of a base theme hook.
 */
function test_theme_theme_test_preprocess_suggestions__kitten__meerkat($variables) {
  return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
}

/**
 * Tests a theme overriding a default hook with a suggestion.
 *
 * Implements hook_preprocess_HOOK().
 */
function test_theme_preprocess_theme_test_preprocess_suggestions(&$variables) {
  $variables['foo'] = 'Theme hook implementor=test_theme_preprocess_theme_test_preprocess_suggestions().';
}

/**
 * Tests a theme overriding a default hook with a suggestion.
 */
function test_theme_preprocess_theme_test_preprocess_suggestions__suggestion(&$variables) {
  $variables['foo'] = 'Suggestion';
}

/**
 * Tests a theme overriding a default hook with a suggestion.
 */
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten(&$variables) {
  $variables['foo'] = 'Kitten';
}

/**
 * Tests a theme overriding a default hook with a suggestion.
 */
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__flamingo(&$variables) {
  $variables['bar'] = 'Flamingo';
}

/**
 * Tests a preprocess function with suggestions.
 */
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose(&$variables) {
  $variables['bar'] = 'Moose';
}