@@ -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($_form ) ' );
35- $ me ->addMacro ('formContainer ' , [$ me , 'macroFormContainer ' ], '$formContainer = $_form = array_pop($_formStack ) ' );
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 ) ' );
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 = '
64+ 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsCurrent = '
6565 . ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
6666 . '$this->global->uiControl[%node.word], %node.array) '
6767 );
@@ -82,7 +82,9 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer)
8282 }
8383 $ node ->tokenizer ->reset ();
8484 return $ writer ->write (
85- '$_formStack[] = $_form; $formContainer = $_form = ' . ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' ) . '$_form[%node.word] '
85+ '$this->global->formsStack[] = $this->global->formsCurrent; $formContainer = $_form = $this->global->formsCurrent = '
86+ . ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
87+ . '$this->global->formsCurrent[%node.word] '
8688 );
8789 }
8890
@@ -102,7 +104,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
102104 $ node ->replaced = true ;
103105 $ name = array_shift ($ words );
104106 return $ writer ->write (
105- ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : $_form [%0.word]; if ($_label = $_input ' : 'if ($_label = $_form [%0.word] ' )
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] ' )
106108 . '->%1.raw) echo $_label '
107109 . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' ),
108110 $ name ,
@@ -138,7 +140,7 @@ public function macroInput(MacroNode $node, PhpWriter $writer)
138140 $ node ->replaced = true ;
139141 $ name = array_shift ($ words );
140142 return $ writer ->write (
141- ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : $_form [%0.word]; echo $_input ' : 'echo $_form [%0.word] ' )
143+ ($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : $this->global->formsCurrent [%0.word]; echo $_input ' : 'echo $this->global->formsCurrent [%0.word] ' )
142144 . '->%1.raw '
143145 . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' ),
144146 $ name ,
@@ -162,7 +164,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
162164
163165 if ($ tagName === 'form ' ) {
164166 return $ writer ->write (
165- 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = '
167+ 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsCurrent = '
166168 . ($ name [0 ] === '$ ' ? 'is_object(%0.word) ? %0.word : ' : '' )
167169 . '$this->global->uiControl[%0.word], %1.var, FALSE) ' ,
168170 $ name ,
@@ -172,7 +174,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
172174 $ method = $ tagName === 'label ' ? 'getLabel ' : 'getControl ' ;
173175 return $ writer ->write (
174176 '$_input = ' . ($ name [0 ] === '$ ' ? 'is_object(%0.word) ? %0.word : ' : '' )
175- . '$_form [%0.word]; echo $_input->%1.raw '
177+ . '$this->global->formsCurrent [%0.word]; echo $_input->%1.raw '
176178 . ($ node ->htmlNode ->attrs ? '->addAttributes(%2.var) ' : '' ) . '->attributes() ' ,
177179 $ name ,
178180 $ words
@@ -198,7 +200,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
198200 {
199201 $ tagName = strtolower ($ node ->htmlNode ->name );
200202 if ($ tagName === 'form ' ) {
201- $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form , FALSE) ?> ' ;
203+ $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent , FALSE) ?> ' ;
202204 } elseif ($ tagName === 'label ' ) {
203205 if ($ node ->htmlNode ->isEmpty ) {
204206 $ node ->innerContent = "<?php echo \$_input->{method_exists( \$_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?> " ;
@@ -226,9 +228,9 @@ public function macroInputError(MacroNode $node, PhpWriter $writer)
226228 if (!$ name ) {
227229 return $ writer ->write ('echo %escape($_input->getError()) ' );
228230 } elseif ($ name [0 ] === '$ ' ) {
229- return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : $_form [%0.word]; echo %escape($_input->getError()) ' , $ name );
231+ return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : $this->global->formsCurrent [%0.word]; echo %escape($_input->getError()) ' , $ name );
230232 } else {
231- return $ writer ->write ('echo %escape($_form [%0.word]->getError()) ' , $ name );
233+ return $ writer ->write ('echo %escape($this->global->formsCurrent [%0.word]->getError()) ' , $ name );
232234 }
233235 }
234236
0 commit comments