Version 1
[yaffs-website] / web / core / modules / system / tests / modules / twig_theme_test / twig_theme_test.module
1 <?php
2
3 /**
4  * @file
5  * Test module.
6  */
7
8 /**
9  * Implements hook_theme().
10  */
11 function twig_theme_test_theme($existing, $type, $theme, $path) {
12   $items['twig_theme_test_filter'] = [
13     'variables' => ['quote' => [], 'attributes' => []],
14     'template' => 'twig_theme_test.filter',
15   ];
16   $items['twig_theme_test_php_variables'] = [
17     'template' => 'twig_theme_test.php_variables',
18   ];
19   $items['twig_theme_test_trans'] = [
20     'variables' => [],
21     'template' => 'twig_theme_test.trans',
22   ];
23   $items['twig_theme_test_placeholder_outside_trans'] = [
24     'variables' => ['var' => ''],
25     'template' => 'twig_theme_test.placeholder_outside_trans',
26   ];
27   $items['twig_namespace_test'] = [
28     'variables' => [],
29     'template' => 'twig_namespace_test',
30   ];
31   $items['twig_registry_loader_test'] = [
32     'variables' => [],
33   ];
34   $items['twig_registry_loader_test_include'] = [
35     'variables' => [],
36   ];
37   $items['twig_registry_loader_test_extend'] = [
38     'variables' => [],
39   ];
40   $items['twig_raw_test'] = [
41     'variables' => ['script' => ''],
42   ];
43   $items['twig_autoescape_test'] = [
44     'variables' => ['script' => ''],
45   ];
46   $items['twig_theme_test_url_generator'] = [
47     'variables' => [],
48     'template' => 'twig_theme_test.url_generator',
49   ];
50   $items['twig_theme_test_link_generator'] = [
51     'variables' => [
52       'test_url' => NULL,
53       'test_url_attribute' => NULL,
54       'attributes' => [],
55     ],
56     'template' => 'twig_theme_test.link_generator',
57   ];
58   $items['twig_theme_test_url_to_string'] = [
59     'variables' => ['test_url' => NULL],
60     'template' => 'twig_theme_test.url_to_string',
61   ];
62   $items['twig_theme_test_file_url'] = [
63     'variables' => [],
64     'template' => 'twig_theme_test.file_url',
65   ];
66   $items['twig_theme_test_attach_library'] = [
67     'variables' => [],
68     'template' => 'twig_theme_test.attach_library',
69   ];
70   $items['twig_theme_test_renderable'] = [
71     'variables' => [
72       'renderable' => NULL,
73     ],
74     'template' => 'twig_theme_test.renderable',
75   ];
76   return $items;
77 }
78
79 /**
80  * Helper function to test PHP variables in the Twig engine.
81  */
82 function _test_theme_twig_php_values() {
83   // Prefix each variable with "twig_" so that Twig doesn't get confused
84   // between a variable and a primitive. Arrays are not tested since they should
85   // be a Drupal render array.
86   return [
87     'twig_null' => [
88       'value' => NULL,
89       'expected' => '',
90     ],
91     'twig_bool_false' => [
92       'value' => FALSE,
93       'expected' => '',
94     ],
95     'twig_bool_true' => [
96       'value' => TRUE,
97       'expected' => '1',
98     ],
99     'twig_int' => [
100       'value' => 1,
101       'expected' => '1',
102     ],
103     'twig_int_0' => [
104       'value' => 0,
105       'expected' => '0',
106     ],
107     'twig_float' => [
108       'value' => 122.34343,
109       'expected' => '122.34343',
110     ],
111     'twig_string' => [
112       'value' => 'Hello world!',
113       'expected' => 'Hello world!',
114     ],
115   ];
116 }
117
118 /**
119  * Implements template_preprocess_status_messages().
120  */
121 function twig_theme_test_preprocess_status_messages(&$variables) {
122   $variables['attributes']['class'][] = 'custom-test-messages-class';
123 }