5 * Theme to help test the Twig engine.
9 * Implements THEME_preprocess_twig_theme_test_php_variables().
11 function test_theme_preprocess_twig_theme_test_php_variables(&$variables) {
12 $variables['php_values'] = _test_theme_twig_php_values();
16 * Tests a theme overriding a suggestion of a base theme hook.
18 function test_theme_theme_test__suggestion($variables) {
19 return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
23 * Implements hook_element_info_alter().
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;
33 * Implements hook_library_info_alter().
35 function test_theme_library_info_alter(&$libraries, $extension) {
36 if ($extension === 'test_theme') {
37 $libraries['kitten']['js']['kittens.js'] = [];
42 * Tests a theme implementing an alter hook.
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').
48 function test_theme_theme_test_alter_alter(&$data) {
49 $data = 'test_theme_theme_test_alter_alter was invoked';
53 * Implements hook_theme_suggestions_alter().
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
61 if ($hook == 'theme_test_general_suggestions') {
62 array_unshift($suggestions, 'theme_test_general_suggestions__' . 'theme_override');
67 * Implements hook_theme_suggestions_HOOK_alter().
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
75 array_unshift($suggestions, 'theme_test_suggestions__' . 'theme_override');
79 * Implements hook_theme_suggestions_HOOK_alter().
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
86 array_unshift($suggestions, 'theme_test_function_suggestions__' . 'theme_override');
90 * Returns HTML for a theme function suggestion test.
92 * Implements the theme_test_function_suggestions__theme_override suggestion.
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.';
99 * Returns HTML for a theme function suggestion test.
101 * Implements the theme_test_function_suggestions__module_override suggestion.
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.';
108 * Implements hook_theme_registry_alter().
110 function test_theme_theme_registry_alter(&$registry) {
111 $registry['theme_test_template_test']['variables']['additional'] = 'value';
115 * Tests a theme overriding a suggestion of a base theme hook.
117 function test_theme_theme_test_preprocess_suggestions__kitten__meerkat($variables) {
118 return 'Theme hook implementor=test_theme_theme_test__suggestion(). Foo=' . $variables['foo'];
122 * Tests a theme overriding a default hook with a suggestion.
124 * Implements hook_preprocess_HOOK().
126 function test_theme_preprocess_theme_test_preprocess_suggestions(&$variables) {
127 $variables['foo'] = 'Theme hook implementor=test_theme_preprocess_theme_test_preprocess_suggestions().';
131 * Tests a theme overriding a default hook with a suggestion.
133 function test_theme_preprocess_theme_test_preprocess_suggestions__suggestion(&$variables) {
134 $variables['foo'] = 'Suggestion';
138 * Tests a theme overriding a default hook with a suggestion.
140 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten(&$variables) {
141 $variables['foo'] = 'Kitten';
145 * Tests a theme overriding a default hook with a suggestion.
147 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__flamingo(&$variables) {
148 $variables['bar'] = 'Flamingo';
152 * Tests a preprocess function with suggestions.
154 function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose(&$variables) {
155 $variables['bar'] = 'Moose';