Commit dce608f5 authored by webchick's avatar webchick
Browse files

#674784 by JohnAlbin, naxoc, et al: Fixed theme_get_suggestions() fails to...

#674784 by JohnAlbin, naxoc, et al: Fixed theme_get_suggestions() fails to return 'page__front()' suggestion on front page.
parent 124f83e7
...@@ -2460,20 +2460,22 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { ...@@ -2460,20 +2460,22 @@ function theme_get_suggestions($args, $base, $delimiter = '__') {
// page__node__edit page-node-edit // page__node__edit page-node-edit
$suggestions = array(); $suggestions = array();
$prefix = $base;
foreach ($args as $arg) { foreach ($args as $arg) {
// Remove slashes or null per SA-CORE-2009-003. // Remove slashes or null per SA-CORE-2009-003.
$arg = str_replace(array("/", "\\", "\0"), '', $arg); $arg = str_replace(array("/", "\\", "\0"), '', $arg);
// The percent acts as a wildcard for numeric arguments since // The percent acts as a wildcard for numeric arguments since
// asterisks are not valid filename characters on many filesystems. // asterisks are not valid filename characters on many filesystems.
if (is_numeric($arg)) { if (is_numeric($arg)) {
$suggestions[] = $base . $delimiter . '%'; $suggestions[] = $prefix . $delimiter . '%';
} }
$suggestions[] = $base . $delimiter . $arg; $suggestions[] = $prefix . $delimiter . $arg;
if (!is_numeric($arg)) { if (!is_numeric($arg)) {
$base .= $delimiter . $arg; $prefix .= $delimiter . $arg;
} }
} }
if (drupal_is_front_page()) { if (drupal_is_front_page()) {
// Front templates should be based on root only, not prefixed arguments.
$suggestions[] = $base . $delimiter . 'front'; $suggestions[] = $base . $delimiter . 'front';
} }
......
...@@ -39,6 +39,20 @@ class TemplateUnitTest extends DrupalWebTestCase { ...@@ -39,6 +39,20 @@ class TemplateUnitTest extends DrupalWebTestCase {
$suggestions = theme_get_suggestions($args, 'page'); $suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions')); $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions'));
} }
/**
* Ensure page-front template suggestion is added when on front page.
*/
function testFrontPageThemeSuggestion() {
$q = $_GET['q'];
// Set $_GET['q'] to node because theme_get_suggestions() will query it to
// see if we are on the front page.
$_GET['q'] = variable_get('site_frontpage', 'node');
$suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
// Set it back to not annoy the batch runner.
$_GET['q'] = $q;
$this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.'));
}
} }
/** /**
......
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