Permalink
Browse files

FIX Template discovery on themed Layout templates

Was failing when 'main' template only exists in theme,
but 'Layout' template only exists in module.
  • Loading branch information...
1 parent cef955c commit 5efae23cb29158c109b80683d218fc2d7ce51f71 @chillu chillu committed Apr 29, 2013
View
8 core/manifest/TemplateLoader.php
@@ -75,15 +75,15 @@ public function findTemplates($templates, $theme = null) {
}
if ($found = $this->getManifest()->getCandidateTemplate($template, $theme)) {
- if ($type && isset($found[$type])) {
+ if ($type && isset($found[$type])) {
$found = array(
'main' => $found[$type]
);
+ }
+
+ $result = array_merge($found, $result);
}
-
- $result = array_merge($found, $result);
}
- }
return $result;
}
View
4 core/manifest/TemplateManifest.php
@@ -115,11 +115,11 @@ public function getCandidateTemplate($name, $theme = null) {
if ($this->project && isset($candidates[$this->project])) {
$found = $candidates[$this->project];
} else if ($theme && isset($candidates['themes'][$theme])) {
- $found = $candidates['themes'][$theme];
+ $found = array_merge($candidates, $candidates['themes'][$theme]);
} else {
- unset($candidates['themes']);
$found = $candidates;
}
+ if(isset($found['themes'])) unset($found['themes']);
return $found;
}
View
7 tests/core/manifest/TemplateLoaderTest.php
@@ -42,6 +42,13 @@ public function testFindTemplates() {
);
$this->assertEquals($expectCustomPage, $loader->findTemplates(array('CustomPage', 'Page')));
+
+ // 'main' template only exists in theme, and 'Layout' template only exists in module
+ $expectCustomThemePage = array(
+ 'main' => "$base/themes/theme/templates/CustomThemePage.ss",
+ 'Layout' => "$base/module/templates/Layout/CustomThemePage.ss"
+ );
+ $this->assertEquals($expectCustomThemePage, $loader->findTemplates(array('CustomThemePage', 'Page'), 'theme'));
}
public function testFindTemplatesApplicationOverridesModule() {
View
9 tests/core/manifest/TemplateManifestTest.php
@@ -47,6 +47,13 @@ public function testGetTemplates() {
'subfolder' => array(
'main' => "{$this->base}/module/subfolder/templates/Subfolder.ss"
),
+ 'customthemepage' => array (
+ 'Layout' => "{$this->base}/module/templates/Layout/CustomThemePage.ss",
+ 'themes' =>
+ array(
+ 'theme' => array('main' => "{$this->base}/themes/theme/templates/CustomThemePage.ss",)
+ )
+ ),
'include' => array('themes' => array(
'theme' => array(
'Includes' => "{$this->base}/themes/theme/templates/Includes/Include.ss"
@@ -66,7 +73,7 @@ public function testGetTemplates() {
ksort($expectTests);
ksort($manifest);
ksort($manifestTests);
-
+
$this->assertEquals(
$expect, $manifest,
'All templates are correctly loaded in the manifest.'
View
0 tests/core/manifest/fixtures/templatemanifest/module/templates/Layout/CustomThemePage.ss
No changes.
View
0 tests/core/manifest/fixtures/templatemanifest/themes/theme/templates/CustomThemePage.ss
No changes.

0 comments on commit 5efae23

Please sign in to comment.