Commit d0fb1ad5 authored by catch's avatar catch

Issue #342350 by Deciphered: Fixed Override template files based on template...

Issue #342350 by Deciphered: Fixed Override template files based on template filename as well as hook name.
parent feb983dd
......@@ -1199,10 +1199,10 @@ function drupal_find_theme_templates($cache, $extension, $path) {
if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {
continue;
}
// 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($template, '.')) !== FALSE) {
// 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);
}
// Transform - in filenames to _ to match function naming scheme
......@@ -1214,6 +1214,19 @@ function drupal_find_theme_templates($cache, $extension, $path) {
'path' => dirname($file->uri),
);
}
// Match templates based on the 'template' filename.
foreach ($cache as $hook => $info) {
if (isset($info['template'])) {
$template_candidates = array($info['template'], str_replace($info['theme path'] . '/', '', $info['template']));
if (in_array($template, $template_candidates)) {
$implementations[$hook] = array(
'template' => $template,
'path' => dirname($file->uri),
);
}
}
}
}
// Find templates that implement possible "suggestion" variants of registered
......
......@@ -101,6 +101,15 @@ class ThemeUnitTest extends DrupalWebTestCase {
$this->drupalGet('theme-test/suggestion');
variable_set('preprocess_css', 0);
}
/**
* Ensures a themes template is overrideable based on the 'template' filename.
*/
function testTemplateOverride() {
variable_set('theme_default', 'test_theme');
$this->drupalGet('theme-test/template-test');
$this->assertText('Success: Template overridden.', t('Template overridden by defined \'template\' filename.'));
}
}
/**
......
<?php
/**
* Implements hook_theme().
*/
function theme_test_theme($existing, $type, $theme, $path) {
$items['theme_test_template_test'] = array(
'template' => 'theme_test.template_test',
);
return $items;
}
/**
* Implements hook_menu().
*/
......@@ -23,6 +34,11 @@ function theme_test_menu() {
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['theme-test/template-test'] = array(
'page callback' => 'theme_test_template_test_page_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
......@@ -69,6 +85,13 @@ function theme_test_hook_init_page_callback() {
return $GLOBALS['theme_test_output'];
}
/**
* Menu callback for testing template overridding based on filename.
*/
function theme_test_template_test_page_callback() {
return theme('theme_test_template_test');
}
/**
* Custom theme callback.
*/
......
<!-- Output for Theme API test -->
Fail: Template not overridden.
<!-- Output for Theme API test -->
Success: Template overridden.
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