Skip to content

Commit 2fc11a3

Browse files
committed
Presenter::formatLayoutTemplateFiles() finds layouts in parent presenters locations (BC break)
1 parent e412a9a commit 2fc11a3

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/Application/UI/Presenter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ public function formatLayoutTemplateFiles()
506506
$name = $this->getName();
507507
$presenter = substr($name, strrpos(':' . $name, ':'));
508508
$layout = $this->layout ? $this->layout : 'layout';
509-
$dir = dirname($this->getReflection()->getFileName());
509+
$rc = $this->getReflection();
510+
$dir = dirname($rc->getFileName());
510511
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
511512
$list = [
512513
"$dir/templates/$presenter/@$layout.latte",
@@ -516,6 +517,10 @@ public function formatLayoutTemplateFiles()
516517
$list[] = "$dir/templates/@$layout.latte";
517518
$dir = dirname($dir);
518519
} while ($dir && ($name = substr($name, 0, strrpos($name, ':'))));
520+
521+
while (($rc = $rc->getParentClass()) && $rc->getName() !== __CLASS__) {
522+
$list[] = dirname($rc->getFileName()) . "/templates/@$layout.latte";
523+
}
519524
return $list;
520525
}
521526

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([
3434
__DIR__ . '/templates/Two/@layout.latte',
3535
__DIR__ . '/templates/Two.@layout.latte',
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)