Skip to content

Commit c8f4f95

Browse files
committed
FormMacros: creates $form before <form n:name> is rendered
1 parent 10f9c35 commit c8f4f95

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/Bridges/FormsLatte/FormMacros.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,14 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
165165
$node->empty = $tagName === 'input';
166166

167167
if ($tagName === 'form') {
168+
$node->openingCode = $writer->write(
169+
'<?php $form = $_form = $this->global->formsStack[] = '
170+
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
171+
. '$this->global->uiControl[%0.word]; ?>',
172+
$name
173+
);
168174
return $writer->write(
169-
'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
170-
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
171-
. '$this->global->uiControl[%0.word], %1.var, FALSE)',
172-
$name,
175+
'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %0.var, FALSE)',
173176
array_fill_keys(array_keys($node->htmlNode->attrs), NULL)
174177
);
175178
} else {

tests/Forms.Latte/expected/FormMacros.button.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ class Template%a% extends Latte\Runtime\Template
66

77
function render()
88
{
9-
%A%<form<?php
10-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
9+
%A%
10+
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
11+
?><form<?php
12+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
1113
), FALSE) ?>>
1214
<button<?php
1315
$_input = end($this->global->formsStack)["send"];

tests/Forms.Latte/expected/FormMacros.forms.phtml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ class Template%a% extends Latte\Runtime\Template
191191

192192

193193
<?php
194+
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
194195
if (1) {
195196
?><form id="myForm" class="ajax"<?php
196-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
197+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
197198
'id' => NULL,
198199
'class' => NULL,
199200
), FALSE) ?>>
@@ -208,8 +209,10 @@ class Template%a% extends Latte\Runtime\Template
208209
?>
209210

210211

211-
<FORM<?php
212-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = is_object($this->global->uiControl['myForm']) ? $this->global->uiControl['myForm'] : $this->global->uiControl[$this->global->uiControl['myForm']], array (
212+
<?php
213+
$form = $_form = $this->global->formsStack[] = is_object($this->global->uiControl['myForm']) ? $this->global->uiControl['myForm'] : $this->global->uiControl[$this->global->uiControl['myForm']];
214+
?><FORM<?php
215+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
213216
), FALSE) ?>>
214217
<input<?php
215218
$_input = end($this->global->formsStack)["username"];

tests/Forms.Latte/expected/FormMacros.get.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
?>
66

77

8-
<form<?php
9-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
8+
<?php
9+
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
10+
?><form<?php
11+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
1012
), FALSE) ?>>
1113
<?php
1214
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), FALSE);

0 commit comments

Comments
 (0)