@@ -31,8 +31,8 @@ class FormMacros extends MacroSet
3131 public static function install (Latte \Compiler $ compiler )
3232 {
3333 $ me = new static ($ compiler );
34- $ me ->addMacro ('form ' , [$ me , 'macroForm ' ], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent) ' );
35- $ me ->addMacro ('formContainer ' , [$ me , 'macroFormContainer ' ], '$formContainer = $_form = $ this->global->formsCurrent = array_pop ($this->global->formsStack) ' );
34+ $ me ->addMacro ('form ' , [$ me , 'macroForm ' ], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop( $this->global->formsStack)); ' );
35+ $ me ->addMacro ('formContainer ' , [$ me , 'macroFormContainer ' ], 'array_pop($ this->global->formsStack); $formContainer = $_form = end ($this->global->formsStack) ' );
3636 $ me ->addMacro ('label ' , [$ me , 'macroLabel ' ], [$ me , 'macroLabelEnd ' ], NULL , self ::AUTO_EMPTY );
3737 $ me ->addMacro ('input ' , [$ me , 'macroInput ' ]);
3838 $ me ->addMacro ('name ' , [$ me , 'macroName ' ], [$ me , 'macroNameEnd ' ], [$ me , 'macroNameAttr ' ]);
@@ -61,7 +61,7 @@ public function macroForm(MacroNode $node, PhpWriter $writer)
6161 $ node ->replaced = true ;
6262 $ node ->tokenizer ->reset ();
6363 return $ writer ->write (
64- 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsCurrent = '
64+ 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
6565 . ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
6666 . '$this->global->uiControl[%node.word], %node.array) '
6767 );
@@ -82,9 +82,9 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer)
8282 }
8383 $ node ->tokenizer ->reset ();
8484 return $ writer ->write (
85- '$this->global->formsStack[] = $this->global->formsCurrent; $ formContainer = $_form = $this->global->formsCurrent = '
85+ '$this->global->formsStack[] = $formContainer = $_form = '
8686 . ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
87- . '$this->global->formsCurrent [%node.word] '
87+ . 'end( $this->global->formsStack) [%node.word] '
8888 );
8989 }
9090
@@ -104,7 +104,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
104104 $ node ->replaced = true ;
105105 $ name = array_shift ($ words );
106106 return $ writer ->write (
107- ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : $this->global->formsCurrent [%0.word]; if ($_label = $_input ' : 'if ($_label = $this->global->formsCurrent [%0.word] ' )
107+ ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : end( $this->global->formsStack) [%0.word]; if ($_label = $_input ' : 'if ($_label = end( $this->global->formsStack) [%0.word] ' )
108108 . '->%1.raw) echo $_label '
109109 . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' ),
110110 $ name ,
@@ -140,7 +140,7 @@ public function macroInput(MacroNode $node, PhpWriter $writer)
140140 $ node ->replaced = true ;
141141 $ name = array_shift ($ words );
142142 return $ writer ->write (
143- ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : $this->global->formsCurrent [%0.word]; echo $_input ' : 'echo $this->global->formsCurrent [%0.word] ' )
143+ ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : end( $this->global->formsStack) [%0.word]; echo $_input ' : 'echo end( $this->global->formsStack) [%0.word] ' )
144144 . '->%1.raw '
145145 . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' ),
146146 $ name ,
@@ -164,7 +164,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
164164
165165 if ($ tagName === 'form ' ) {
166166 return $ writer ->write (
167- 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsCurrent = '
167+ 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
168168 . ($ name [0 ] === '$ ' ? 'is_object(%0.word) ? %0.word : ' : '' )
169169 . '$this->global->uiControl[%0.word], %1.var, FALSE) ' ,
170170 $ name ,
@@ -174,7 +174,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
174174 $ method = $ tagName === 'label ' ? 'getLabel ' : 'getControl ' ;
175175 return $ writer ->write (
176176 '$_input = ' . ($ name [0 ] === '$ ' ? 'is_object(%0.word) ? %0.word : ' : '' )
177- . '$this->global->formsCurrent [%0.word]; echo $_input->%1.raw '
177+ . 'end( $this->global->formsStack) [%0.word]; echo $_input->%1.raw '
178178 . ($ node ->htmlNode ->attrs ? '->addAttributes(%2.var) ' : '' ) . '->attributes() ' ,
179179 $ name ,
180180 $ method . 'Part( ' . implode (', ' , array_map ([$ writer , 'formatWord ' ], $ words )) . ') ' ,
@@ -198,7 +198,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
198198 {
199199 $ tagName = strtolower ($ node ->htmlNode ->name );
200200 if ($ tagName === 'form ' ) {
201- $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent , FALSE) ?> ' ;
201+ $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop( $this->global->formsStack) , FALSE) ?> ' ;
202202 } elseif ($ tagName === 'label ' ) {
203203 if ($ node ->htmlNode ->isEmpty ) {
204204 $ node ->innerContent = "<?php echo \$_input->getLabelPart()->getHtml() ?> " ;
@@ -226,9 +226,9 @@ public function macroInputError(MacroNode $node, PhpWriter $writer)
226226 if (!$ name ) {
227227 return $ writer ->write ('echo %escape($_input->getError()) ' );
228228 } elseif ($ name [0 ] === '$ ' ) {
229- return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : $this->global->formsCurrent [%0.word]; echo %escape($_input->getError()) ' , $ name );
229+ return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : end( $this->global->formsStack) [%0.word]; echo %escape($_input->getError()) ' , $ name );
230230 } else {
231- return $ writer ->write ('echo %escape($this->global->formsCurrent [%0.word]->getError()) ' , $ name );
231+ return $ writer ->write ('echo %escape(end( $this->global->formsStack) [%0.word]->getError()) ' , $ name );
232232 }
233233 }
234234
0 commit comments