Commit 16483763 authored by alexpott's avatar alexpott

Issue #2574717 by dawehner, hussainweb, lauriii, pwolanin, davidhernandez,...

Issue #2574717 by dawehner, hussainweb, lauriii, pwolanin, davidhernandez, xjm, stefan.r, webchick, Wim Leers: Remove PHPTemplate, and add test coverage for multiple theme engine support
parent 24ed79e1
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\system\Tests\Theme\EnginePhpTemplateTest.
* Contains \Drupal\system\Tests\Theme\EngineNyanCatTest.
*/
namespace Drupal\system\Tests\Theme;
......@@ -10,11 +10,11 @@
use Drupal\simpletest\WebTestBase;
/**
* Tests theme functions with PHPTemplate.
* Tests the multi theme engine support.
*
* @group Theme
*/
class EnginePhpTemplateTest extends WebTestBase {
class EngineNyanCatTest extends WebTestBase {
/**
* Modules to enable.
......@@ -25,7 +25,7 @@ class EnginePhpTemplateTest extends WebTestBase {
protected function setUp() {
parent::setUp();
\Drupal::service('theme_handler')->install(array('test_theme_phptemplate'));
\Drupal::service('theme_handler')->install(array('test_theme_nyan_cat_engine'));
}
/**
......@@ -33,10 +33,10 @@ protected function setUp() {
*/
function testTemplateOverride() {
$this->config('system.theme')
->set('default', 'test_theme_phptemplate')
->set('default', 'test_theme_nyan_cat_engine')
->save();
$this->drupalGet('theme-test/template-test');
$this->assertText('Success: Template overridden with PHPTemplate theme.', 'Template overridden by PHPTemplate file.');
$this->assertText('Success: Template overridden with Nyan Cat theme. All of them', 'Template overridden by Nyan Cat file.');
}
}
......@@ -2,7 +2,7 @@
/**
* @file
* Handles integration of PHP templates with the Drupal theme system.
* Handles integration of Nyan cat templates because we love kittens.
*/
use Drupal\Core\Extension\Extension;
......@@ -10,49 +10,43 @@
/**
* Implements hook_init().
*/
function phptemplate_init(Extension $theme) {
function nyan_cat_init(Extension $theme) {
$theme->load();
}
/**
* Implements hook_theme().
*/
function phptemplate_theme($existing, $type, $theme, $path) {
function nyan_cat_theme($existing, $type, $theme, $path) {
$templates = drupal_find_theme_functions($existing, array($theme));
$templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
$templates += drupal_find_theme_templates($existing, '.nyan-cat.html', $path);
return $templates;
}
/**
* Implements hook_extension().
*/
function phptemplate_extension() {
return '.tpl.php';
function nyan_cat_extension() {
return '.nyan-cat.html';
}
/**
* Implements hook_render_template().
*
* Renders a system default template, which is essentially a PHP template.
*
* @param $template_file
* @param string $template_file
* The filename of the template to render.
* @param $variables
* @param mixed[] $variables
* A keyed array of variables that will appear in the output.
*
* @return
* @return string
* 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();
function nyan_cat_render_template($template_file, $variables) {
$output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file));
foreach ($variables as $key => $variable) {
if (strpos($output, '9' . $key) !== FALSE) {
$output = str_replace('9' . $key, theme_render_and_autoescape($variable), $output);
}
}
return $output;
}
name: 'Test theme for Nyan Cat engine'
type: theme
description: 'Theme for testing the theme system with the Nyan Cat theme engine'
version: VERSION
core: 8.x
engine: nyan_cat
<?php
/**
* Implements hook_preprocess_theme_test_template_test().
*/
function test_theme_nyan_cat_engine_preprocess_theme_test_template_test(&$variables) {
$variables['kittens'] = 'All of them';
}
<?php
// node--1.tpl.php - Dummy file for finding the template
?>
Node Content Dummy
name: 'Test theme PHPTemplate'
type: theme
description: 'Theme for testing the theme system with the PHPTemplate engine'
version: VERSION
core: 8.x
engine: phptemplate
<!-- Output for Theme API test -->
<?php print 'Success: Template overridden with PHPTemplate theme.'; ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment