Skip to content

Commit 0b2e1e0

Browse files
committed
UIMacro: parent template retrieving moved to UIRuntime
1 parent 3aa6f65 commit 0b2e1e0

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ public function initialize()
6060
*/
6161
public function finalize()
6262
{
63-
return [
64-
'Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this)',
65-
'',
66-
$this->extends ? '' : '$this->parentName = $this->parentName ?: ($this->blocks && !$this->getReferringTemplate()
67-
&& isset($this->global->uiControl) && $this->global->uiControl instanceof Nette\Application\UI\Presenter
68-
? $this->global->uiControl->findLayoutTemplateFile() : NULL);',
69-
];
63+
return [$this->extends . 'Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->parentName, $this->blocks);'];
7064
}
7165

7266

@@ -146,11 +140,10 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
146140
*/
147141
public function macroExtends(MacroNode $node, PhpWriter $writer)
148142
{
149-
$this->extends = TRUE;
150143
if ($node->modifiers || $node->parentNode || $node->args !== 'auto') {
151-
return FALSE;
144+
return $this->extends = FALSE;
152145
}
153-
return $writer->write('$this->parentName = $this->global->uiPresenter->findLayoutTemplateFile();');
146+
$this->extends = $writer->write('$this->parentName = $this->global->uiPresenter->findLayoutTemplateFile();');
154147
}
155148

156149

src/Bridges/ApplicationLatte/UIRuntime.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Nette\Bridges\ApplicationLatte;
99

1010
use Nette;
11-
use Nette\Application\UI;
1211
use Latte;
1312

1413

@@ -21,19 +20,26 @@ class UIRuntime
2120
use Nette\StaticClass;
2221

2322
/**
24-
* @return bool
23+
* @return void
2524
*/
26-
public static function initialize(Latte\Runtime\Template $template)
25+
public static function initialize(Latte\Runtime\Template $template, & $parentName, array $blocks)
2726
{
27+
$providers = $template->global;
28+
if (!$parentName && $blocks && !$template->getReferringTemplate()
29+
&& isset($providers->uiControl) && $providers->uiControl instanceof Nette\Application\UI\Presenter
30+
) {
31+
$parentName = $providers->uiControl->findLayoutTemplateFile();
32+
}
33+
2834
// back compatiblity
2935
$params = $template->getParameters();
30-
if (empty($template->global->uiControl) && isset($params['_control'])) {
36+
if (empty($providers->uiControl) && isset($params['_control'])) {
3137
trigger_error('Replace template variable $_control with provider: $latte->addProvider("uiControl", ...)', E_USER_DEPRECATED);
32-
$template->global->uiControl = $params['_control'];
38+
$providers->uiControl = $params['_control'];
3339
}
34-
if (empty($template->global->uiPresenter) && isset($params['_presenter'])) {
40+
if (empty($providers->uiPresenter) && isset($params['_presenter'])) {
3541
trigger_error('Replace template variable $_presenter with provider: $latte->addProvider("uiPresenter", ...)', E_USER_DEPRECATED);
36-
$template->global->uiPresenter = $params['_presenter'];
42+
$providers->uiPresenter = $params['_presenter'];
3743
}
3844
}
3945

0 commit comments

Comments
 (0)