diff --git a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php index e6869467a..2de161e4a 100644 --- a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php +++ b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php @@ -41,7 +41,18 @@ public static function create(Tag $tag): \Generator public function print(PrintContext $context): string { - return $this->content->print($context); + return $context->format( + '$form = $this->global->formsStack[] = ' + . ($this->name instanceof StringNode + ? '$this->global->uiControl[%node]' + : 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') + . ' %line;' + . '%node ' + . 'array_pop($this->global->formsStack);', + $this->name, + $this->position, + $this->content, + ); } @@ -50,14 +61,7 @@ private function init(Tag $tag) $el = $tag->htmlElement; $tag->replaceNAttribute(new AuxiliaryNode(fn(PrintContext $context) => $context->format( - '$form = $this->global->formsStack[] = ' - . ($this->name instanceof StringNode - ? '$this->global->uiControl[%node]' - : 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') - . ' %line;' - . 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %dump, false) %line;', - $this->name, - $this->position, + 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %dump, false) %line;', array_fill_keys(FieldNNameNode::findUsedAttributes($el), null), $this->position, ))); @@ -65,7 +69,7 @@ private function init(Tag $tag) $el->content = new Latte\Compiler\Nodes\FragmentNode([ $el->content, new AuxiliaryNode(fn(PrintContext $context) => $context->format( - 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) %line;', + 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) %line;', $this->position, )), ]); diff --git a/tests/Forms.Latte3/expected/forms.button.php b/tests/Forms.Latte3/expected/forms.button.php index a75a54684..ab94e396a 100644 --- a/tests/Forms.Latte3/expected/forms.button.php +++ b/tests/Forms.Latte3/expected/forms.button.php @@ -1,7 +1,7 @@ global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */; + echo '
'; + array_pop($this->global->formsStack); %A% diff --git a/tests/Forms.Latte3/expected/forms.get.php b/tests/Forms.Latte3/expected/forms.get.php index 358aef9c8..06530d61b 100644 --- a/tests/Forms.Latte3/expected/forms.get.php +++ b/tests/Forms.Latte3/expected/forms.get.php @@ -6,12 +6,14 @@ echo ' - '; + array_pop($this->global->formsStack); %A% diff --git a/tests/Forms.Latte3/expected/forms.php b/tests/Forms.Latte3/expected/forms.php index 38f271e98..c9551ec81 100644 --- a/tests/Forms.Latte3/expected/forms.php +++ b/tests/Forms.Latte3/expected/forms.php @@ -174,22 +174,24 @@ '; if (1) /* line %d% */ { - echo ' '; + array_pop($this->global->formsStack); } echo ' - +'; + array_pop($this->global->formsStack); + echo ' - - - +'; + array_pop($this->global->formsStack); + echo '