Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / tests / themes / engines / nyan_cat / nyan_cat.engine
1 <?php
2
3 /**
4  * @file
5  * Handles integration of Nyan cat templates because we love kittens.
6  */
7
8 use Drupal\Core\Extension\Extension;
9
10 /**
11  * Includes .theme file from themes.
12  *
13  * @param \Drupal\Core\Extension\Extension $theme
14  *   The theme extension object.
15  */
16 function nyan_cat_init(Extension $theme) {
17   $theme->load();
18 }
19
20 /**
21  * Implements hook_theme().
22  */
23 function nyan_cat_theme($existing, $type, $theme, $path) {
24   $templates = drupal_find_theme_functions($existing, [$theme]);
25   $templates += drupal_find_theme_templates($existing, '.nyan-cat.html', $path);
26   return $templates;
27 }
28
29 /**
30  * Implements hook_extension().
31  */
32 function nyan_cat_extension() {
33   return '.nyan-cat.html';
34 }
35
36 /**
37  * Implements hook_render_template().
38  *
39  * @param string $template_file
40  *   The filename of the template to render.
41  * @param mixed[] $variables
42  *   A keyed array of variables that will appear in the output.
43  *
44  * @return string
45  *   The output generated by the template.
46  */
47 function nyan_cat_render_template($template_file, $variables) {
48   $output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file));
49   foreach ($variables as $key => $variable) {
50     if (strpos($output, '9' . $key) !== FALSE) {
51       $output = str_replace('9' . $key, theme_render_and_autoescape($variable), $output);
52     }
53   }
54   return $output;
55 }