Skip to content

Commit

Permalink
FormMacros: creates $form before <form n:name> is rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 1, 2016
1 parent bcb0685 commit 77ffdfb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/Bridges/FormsLatte/FormMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
$node->empty = $tagName === 'input';

if ($tagName === 'form') {
$node->openingCode = $writer->write(
'<?php $form = $_form = $this->global->formsStack[] = '
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
. '$this->global->uiControl[%0.word]; ?>',
$name
);
return $writer->write(
'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
. '$this->global->uiControl[%0.word], %1.var, FALSE)',
$name,
'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %0.var, FALSE)',
array_fill_keys(array_keys($node->htmlNode->attrs), NULL)
);
} else {
Expand Down
6 changes: 4 additions & 2 deletions tests/Forms.Latte/expected/FormMacros.button.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class Template%a% extends Latte\Runtime\Template

function render()
{
%A%<form<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
%A%
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
?><form<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
), FALSE) ?>>
<button<?php
$_input = end($this->global->formsStack)["send"];
Expand Down
9 changes: 6 additions & 3 deletions tests/Forms.Latte/expected/FormMacros.forms.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ class Template%a% extends Latte\Runtime\Template


<?php
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
if (1) {
?><form id="myForm" class="ajax"<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
'id' => NULL,
'class' => NULL,
), FALSE) ?>>
Expand All @@ -208,8 +209,10 @@ class Template%a% extends Latte\Runtime\Template
?>


<FORM<?php
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 (
<?php
$form = $_form = $this->global->formsStack[] = is_object($this->global->uiControl['myForm']) ? $this->global->uiControl['myForm'] : $this->global->uiControl[$this->global->uiControl['myForm']];
?><FORM<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
), FALSE) ?>>
<input<?php
$_input = end($this->global->formsStack)["username"];
Expand Down
6 changes: 4 additions & 2 deletions tests/Forms.Latte/expected/FormMacros.get.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
?>


<form<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"], array (
<?php
$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
?><form<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array (
), FALSE) ?>>
<?php
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), FALSE);
Expand Down

0 comments on commit 77ffdfb

Please sign in to comment.