Skip to content

Commit cfb7582

Browse files
committed
UIMacros: {control} wrap arguments in array only when needed [Closes nette/nette#1206]
1 parent eba19f3 commit cfb7582

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,19 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
8484
$name = $writer->formatWord($words[0]);
8585
$method = isset($words[1]) ? ucfirst($words[1]) : '';
8686
$method = Strings::match($method, '#^\w*\z#') ? "render$method" : "{\"render$method\"}";
87+
88+
$tokens = $node->tokenizer;
89+
$pos = $tokens->position;
8790
$param = $writer->formatArray();
88-
if (!Strings::contains($node->args, '=>')) {
89-
$param = substr($param, $param[0] === '[' ? 1 : 6, -1); // removes array() or []
91+
$tokens->position = $pos;
92+
while ($tokens->nextToken()) {
93+
if ($tokens->isCurrent('=>') && !$tokens->depth) {
94+
$wrap = TRUE;
95+
break;
96+
}
97+
}
98+
if (empty($wrap)) {
99+
$param = substr($param, 1, -1); // removes array() or []
90100
}
91101
return ($name[0] === '$' ? "if (is_object($name)) \$_tmp = $name; else " : '')
92102
. '$_tmp = $this->global->uiControl->getComponent(' . $name . '); '

0 commit comments

Comments
 (0)