|
24 | 24 | * - {label name /} or {label name}... {/label} |
25 | 25 | * - {inputError name} |
26 | 26 | * - {formContainer name} ... {/formContainer} |
| 27 | + * - {formContext name} ... {/formContext} |
27 | 28 | */ |
28 | 29 | final class FormMacros extends MacroSet |
29 | 30 | { |
30 | 31 | public static function install(Latte\Compiler $compiler): void |
31 | 32 | { |
32 | 33 | $me = new static($compiler); |
33 | 34 | $me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));'); |
| 35 | + $me->addMacro('formContext', [$me, 'macroFormContext'], 'array_pop($this->global->formsStack);'); |
34 | 36 | $me->addMacro('formContainer', [$me, 'macroFormContainer'], 'array_pop($this->global->formsStack); $formContainer = $_form = end($this->global->formsStack)'); |
35 | 37 | $me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd'], null, self::AUTO_EMPTY); |
36 | 38 | $me->addMacro('input', [$me, 'macroInput']); |
@@ -69,6 +71,30 @@ public function macroForm(MacroNode $node, PhpWriter $writer) |
69 | 71 | } |
70 | 72 |
|
71 | 73 |
|
| 74 | + /** |
| 75 | + * {formContext ...} |
| 76 | + */ |
| 77 | + public function macroFormContext(MacroNode $node, PhpWriter $writer) |
| 78 | + { |
| 79 | + if ($node->modifiers) { |
| 80 | + throw new CompileException('Modifiers are not allowed in ' . $node->getNotation()); |
| 81 | + } |
| 82 | + if ($node->prefix) { |
| 83 | + throw new CompileException('Did you mean <form n:name=...> ?'); |
| 84 | + } |
| 85 | + $name = $node->tokenizer->fetchWord(); |
| 86 | + if ($name == null) { // null or false |
| 87 | + throw new CompileException('Missing form name in ' . $node->getNotation()); |
| 88 | + } |
| 89 | + $node->tokenizer->reset(); |
| 90 | + return $writer->write( |
| 91 | + '$form = $this->global->formsStack[] = ' |
| 92 | + . ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '') |
| 93 | + . '$this->global->uiControl[%node.word];' |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + |
72 | 98 | /** |
73 | 99 | * {formContainer ...} |
74 | 100 | */ |
|
0 commit comments