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
24ed79e134
commit
164837635c
|
@ -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 @@ namespace Drupal\system\Tests\Theme;
|
|||
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 @@ class EnginePhpTemplateTest extends WebTestBase {
|
|||
*/
|
||||
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.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handles integration of Nyan cat templates because we love kittens.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function nyan_cat_init(Extension $theme) {
|
||||
$theme->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function nyan_cat_theme($existing, $type, $theme, $path) {
|
||||
$templates = drupal_find_theme_functions($existing, array($theme));
|
||||
$templates += drupal_find_theme_templates($existing, '.nyan-cat.html', $path);
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_extension().
|
||||
*/
|
||||
function nyan_cat_extension() {
|
||||
return '.nyan-cat.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_render_template().
|
||||
*
|
||||
* @param string $template_file
|
||||
* The filename of the template to render.
|
||||
* @param mixed[] $variables
|
||||
* A keyed array of variables that will appear in the output.
|
||||
*
|
||||
* @return string
|
||||
* The output generated by the template.
|
||||
*/
|
||||
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;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
type: theme_engine
|
||||
name: PHPTemplate
|
||||
name: Nyan cat
|
||||
core: 8.x
|
||||
version: VERSION
|
||||
package: Core
|
|
@ -0,0 +1,6 @@
|
|||
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
|
|
@ -0,0 +1,8 @@
|
|||
<?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';
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Success: Template overridden with Nyan Cat theme. 9kittens
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
// node--1.tpl.php - Dummy file for finding the template
|
||||
?>
|
||||
Node Content Dummy
|
|
@ -1,6 +0,0 @@
|
|||
name: 'Test theme PHPTemplate'
|
||||
type: theme
|
||||
description: 'Theme for testing the theme system with the PHPTemplate engine'
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
engine: phptemplate
|
|
@ -1 +0,0 @@
|
|||
<?php
|
|
@ -1,2 +0,0 @@
|
|||
<!-- Output for Theme API test -->
|
||||
<?php print 'Success: Template overridden with PHPTemplate theme.'; ?>
|
|
@ -1,58 +0,0 @@
|
|||
<?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();
|
||||
}
|
Loading…
Reference in New Issue