5 * Handles integration of Nyan cat templates because we love kittens.
8 use Drupal\Core\Extension\Extension;
11 * Includes .theme file from themes.
13 * @param \Drupal\Core\Extension\Extension $theme
14 * The theme extension object.
16 function nyan_cat_init(Extension $theme) {
21 * Implements hook_theme().
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);
30 * Implements hook_extension().
32 function nyan_cat_extension() {
33 return '.nyan-cat.html';
37 * Implements hook_render_template().
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.
45 * The output generated by the template.
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);