59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Handles integration of PHP templates with the Drupal theme system.
|
|
*/
|
|
|
|
use Drupal\Core\Extension\Extension;
|
|
|
|
/**
|
|
* Implements hook_init().
|
|
*/
|
|
function phptemplate_init(Extension $theme) {
|
|
$theme->load();
|
|
}
|
|
|
|
/**
|
|
* Implements hook_theme().
|
|
*/
|
|
function phptemplate_theme($existing, $type, $theme, $path) {
|
|
$templates = drupal_find_theme_functions($existing, array($theme));
|
|
$templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
|
|
return $templates;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_extension().
|
|
*/
|
|
function phptemplate_extension() {
|
|
return '.tpl.php';
|
|
}
|
|
|
|
/**
|
|
* Implements hook_render_template().
|
|
*
|
|
* Renders a system default template, which is essentially a PHP template.
|
|
*
|
|
* @param $template_file
|
|
* The filename of the template to render.
|
|
* @param $variables
|
|
* A keyed array of variables that will appear in the output.
|
|
*
|
|
* @return
|
|
* The output generated by the template.
|
|
*/
|
|
function phptemplate_render_template($template_file, $variables) {
|
|
// Extract the variables to a local namespace
|
|
extract($variables, EXTR_SKIP);
|
|
|
|
// Start output buffering
|
|
ob_start();
|
|
|
|
// Include the template file
|
|
include \Drupal::root() . '/' . $template_file;
|
|
|
|
// End buffering and return its contents
|
|
return ob_get_clean();
|
|
}
|