Commit d5a893e6 authored by webchick's avatar webchick

Issue #1900458 by Cottser, steveoliver: Use .html.twig instead of .twig file extension.

parent 2ccb0f6c
......@@ -269,7 +269,7 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
// @todo Make twig the default engine and remove this. This is required
// because (by design) the theme system doesn't allow modules to register more
// than one type of extension. We need a temporary backwards compatibility
// layer to allow us to perform core-wide .tpl.php to .twig conversion.
// layer to allow us to perform core-wide .tpl.php to .html.twig conversion.
include_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine';
if (isset($registry_callback)) {
......@@ -514,7 +514,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
// Add two render engines for modules.
// @todo Remove and make twig the default engine.
$render_engines = array(
'.twig' => 'twig',
'.html.twig' => 'twig',
'.tpl.php' => 'phptemplate'
);
......@@ -1281,7 +1281,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
// Escape the periods in the extension.
$regex = '/' . str_replace('.', '\.', $extension) . '$/';
// Get a listing of all template files in the path to search.
$files = file_scan_directory($path, $regex, array('key' => 'name'));
$files = file_scan_directory($path, $regex, array('key' => 'filename'));
// Find templates that implement registered theme hooks and include that in
// what is returned so that the registry knows that the theme has this
......@@ -1291,12 +1291,8 @@ function drupal_find_theme_templates($cache, $extension, $path) {
if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {
continue;
}
// Chop off the remaining '.tpl' extension. $template already has the
// rightmost extension removed, but there might still be more, such as with
// .tpl.php, which still has .tpl in $template at this point.
if (($pos = strpos($template, '.tpl')) !== FALSE) {
$template = substr($template, 0, $pos);
}
// Remove the extension from the filename.
$template = str_replace($extension, '', $template);
// Transform - in filenames to _ to match function naming scheme
// for the purposes of searching.
$hook = strtr($template, '-', '_');
......@@ -1337,13 +1333,8 @@ function drupal_find_theme_templates($cache, $extension, $path) {
if ($matches) {
foreach ($matches as $match) {
$file = $match;
// Chop off the remaining extensions if there are any. $template
// already has the rightmost extension removed, but there might still
// be more, such as with .tpl.php, which still has .tpl in $template
// at this point.
if (($pos = strpos($match, '.')) !== FALSE) {
$file = substr($match, 0, $pos);
}
// Remove the extension from the filename.
$file = str_replace($extension, '', $file);
// Put the underscores back in for the hook name and register this
// pattern.
$arg_name = isset($info['variables']) ? 'variables' : 'render element';
......
......@@ -9,7 +9,7 @@
* or print a subset such as {{ content.field_example }}. Use
* {% hide(content.field_example) %} to temporarily suppress the printing
* of a given element.
* - user_picture: The node author's picture from user-picture.twig.
* - user_picture: The node author's picture from user-picture.html.twig.
* - date: Formatted creation date. Preprocess functions can reformat it by
* calling format_date() with the desired parameters on
* $variables['created'].
......
......@@ -58,13 +58,13 @@ function testFindThemeTemplates() {
// Check for correct content
// @todo Remove this tests once double engine code is removed
$this->assertEqual($cache['node']['template_file'], 'core/modules/node/templates/node.twig', 'Node is using node.twig as template file');
$this->assertEqual($cache['node']['template_file'], 'core/modules/node/templates/node.html.twig', 'Node is using node.html.twig as template file');
$this->assertEqual($cache['node']['engine'], 'twig', 'Node is using twig engine');
$this->assertEqual($cache['theme_test_template_test']['template_file'], 'core/modules/system/tests/modules/theme_test/templates/theme_test.template_test.tpl.php', 'theme_test is using theme_test.template_test.tpl.php as template file');
$this->assertEqual($cache['theme_test_template_test']['engine'], 'phptemplate', 'theme_test is using phptemplate as engine.');
$templates = drupal_find_theme_templates($cache, '.twig', drupal_get_path('theme', 'test_theme_twig'));
$this->assertEqual($templates['node__1']['template'], 'node--1', 'Template node--1.twig was found in test_theme_twig.');
$templates = drupal_find_theme_templates($cache, '.html.twig', drupal_get_path('theme', 'test_theme_twig'));
$this->assertEqual($templates['node__1']['template'], 'node--1', 'Template node--1.html.twig was found in test_theme_twig.');
}
}
{#
// node--1.html.twig - Dummy file for finding the template
#}
Node Content Dummy
{#
// node--1.twig - Dummy file for finding the template
#}
Node Content Dummy
......@@ -10,14 +10,14 @@
* Implements hook_theme().
*/
function twig_theme($existing, $type, $theme, $path) {
return drupal_find_theme_templates($existing, '.twig', $path);
return drupal_find_theme_templates($existing, '.html.twig', $path);
}
/**
* Implements hook_extension().
*/
function twig_extension() {
return '.twig';
return '.html.twig';
}
/**
......@@ -45,7 +45,7 @@ function twig_init($template) {
* The output generated by the template.
*/
function twig_render_template($template_file, $variables) {
$variables['_references']=array();
$variables['_references'] = array();
return drupal_container()->get('twig')->loadTemplate($template_file)->render($variables);
}
......
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