Skip to content

Commit 32a1596

Browse files
committed
Presenter::formatLayoutTemplateFiles() finds layouts in parent presenters locations (BC break)
1 parent 9b54283 commit 32a1596

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Application/UI/Presenter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ public function formatLayoutTemplateFiles()
502502
$name = $this->getName();
503503
$presenter = substr($name, strrpos(':' . $name, ':'));
504504
$layout = $this->layout ? $this->layout : 'layout';
505-
$dir = dirname($this->getReflection()->getFileName());
505+
$rc = $this->getReflection();
506+
$dir = dirname($rc->getFileName());
506507
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
507508
$list = array(
508509
"$dir/templates/$presenter/@$layout.latte",
@@ -512,6 +513,10 @@ public function formatLayoutTemplateFiles()
512513
$list[] = "$dir/templates/@$layout.latte";
513514
$dir = dirname($dir);
514515
} while ($dir && ($name = substr($name, 0, strrpos($name, ':'))));
516+
517+
while (($rc = $rc->getParentClass()) && $rc->getName() !== __CLASS__) {
518+
$list[] = dirname($rc->getFileName()) . "/templates/@$layout.latte";
519+
}
515520
return $list;
516521
}
517522

tests/Application.templates/Presenter.formatLayoutTemplateFiles.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ test(function() { // with subdir templates
2626
});
2727

2828

29-
test(function() { // without subdir templates
29+
test(function() { // without subdir templates & parent presenter
3030
$presenter = new Presenter2;
3131
$presenter->setParent(NULL, 'Two');
3232

3333
Assert::same( array(
3434
__DIR__ . '/templates/Two/@layout.latte',
3535
__DIR__ . '/templates/[email protected]',
3636
__DIR__ . '/templates/@layout.latte',
37+
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
3738
), $presenter->formatLayoutTemplateFiles() );
3839
});
3940

@@ -52,7 +53,7 @@ test(function() { // with module & subdir templates
5253
});
5354

5455

55-
test(function() { // with module & without subdir templates
56+
test(function() { // with module & without subdir templates & parent presenter
5657
$presenter = new Presenter2;
5758
$presenter->setParent(NULL, 'Module:SubModule:Two');
5859

@@ -62,5 +63,6 @@ test(function() { // with module & without subdir templates
6263
__DIR__ . '/templates/@layout.latte',
6364
dirname(__DIR__) . '/templates/@layout.latte',
6465
dirname(dirname(__DIR__)) . '/templates/@layout.latte',
66+
__DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte',
6567
), $presenter->formatLayoutTemplateFiles() );
6668
});

0 commit comments

Comments
 (0)