From d5a893e6ac013322dcefdb3f72d710acefd668af Mon Sep 17 00:00:00 2001 From: webchick Date: Tue, 29 Jan 2013 19:11:25 -0800 Subject: [PATCH] Issue #1900458 by Cottser, steveoliver: Use .html.twig instead of .twig file extension. --- core/includes/theme.inc | 23 ++++++------------- .../templates/{node.twig => node.html.twig} | 2 +- .../system/Tests/Theme/ThemeTestTwig.php | 6 ++--- .../{datetime.twig => datetime.html.twig} | 0 .../themes/test_theme_twig/node--1.html.twig | 4 ++++ .../tests/themes/test_theme_twig/node--1.twig | 4 ---- ...wig => theme_test.template_test.html.twig} | 0 .../{toolbar.twig => toolbar.html.twig} | 0 core/themes/engines/twig/twig.engine | 6 ++--- 9 files changed, 18 insertions(+), 27 deletions(-) rename core/modules/node/templates/{node.twig => node.html.twig} (98%) rename core/modules/system/templates/{datetime.twig => datetime.html.twig} (100%) create mode 100644 core/modules/system/tests/themes/test_theme_twig/node--1.html.twig delete mode 100644 core/modules/system/tests/themes/test_theme_twig/node--1.twig rename core/modules/system/tests/themes/test_theme_twig/{theme_test.template_test.twig => theme_test.template_test.html.twig} (100%) rename core/modules/toolbar/templates/{toolbar.twig => toolbar.html.twig} (100%) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index a38dbe05d1c..79a0b87e462 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -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'; diff --git a/core/modules/node/templates/node.twig b/core/modules/node/templates/node.html.twig similarity index 98% rename from core/modules/node/templates/node.twig rename to core/modules/node/templates/node.html.twig index 2d4a67443ea..f1e0b5aba62 100644 --- a/core/modules/node/templates/node.twig +++ b/core/modules/node/templates/node.html.twig @@ -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']. diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php index 6a9d98815cb..13b649c8d3e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php @@ -58,13 +58,13 @@ class ThemeTestTwig extends WebTestBase { // 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.'); } } diff --git a/core/modules/system/templates/datetime.twig b/core/modules/system/templates/datetime.html.twig similarity index 100% rename from core/modules/system/templates/datetime.twig rename to core/modules/system/templates/datetime.html.twig diff --git a/core/modules/system/tests/themes/test_theme_twig/node--1.html.twig b/core/modules/system/tests/themes/test_theme_twig/node--1.html.twig new file mode 100644 index 00000000000..046c02eea77 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_twig/node--1.html.twig @@ -0,0 +1,4 @@ +{# + // node--1.html.twig - Dummy file for finding the template +#} +Node Content Dummy diff --git a/core/modules/system/tests/themes/test_theme_twig/node--1.twig b/core/modules/system/tests/themes/test_theme_twig/node--1.twig deleted file mode 100644 index 79148f1633e..00000000000 --- a/core/modules/system/tests/themes/test_theme_twig/node--1.twig +++ /dev/null @@ -1,4 +0,0 @@ -{# - // node--1.twig - Dummy file for finding the template -#} -Node Content Dummy diff --git a/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.twig b/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig similarity index 100% rename from core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.twig rename to core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig diff --git a/core/modules/toolbar/templates/toolbar.twig b/core/modules/toolbar/templates/toolbar.html.twig similarity index 100% rename from core/modules/toolbar/templates/toolbar.twig rename to core/modules/toolbar/templates/toolbar.html.twig diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index e496bc9e294..d318263fae6 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -10,14 +10,14 @@ use Drupal\Core\Template\TwigReference; * 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); }