1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class NFormMacros extends NMacroSet
26: {
27:
28: public static function install(NParser $parser)
29: {
30: $me = new self($parser);
31: $me->addMacro('form',
32: '$form = $control[%node.word]; echo $form->getElementPrototype()->addAttributes(%node.array)->startTag()',
33: '?><div><?php
34: foreach ($form->getComponents(TRUE, \'NHiddenField\') as $_tmp) echo $_tmp->getControl();
35: if (iterator_count($form->getComponents(TRUE, \'NTextInput\')) < 2) echo "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->";
36: ?></div>
37: <?php echo $form->getElementPrototype()->endTag()');
38: $me->addMacro('label', array($me, 'macroLabel'), '?></label><?php');
39: $me->addMacro('input', 'echo $form[%node.word]->getControl()->addAttributes(%node.array)');
40: }
41:
42:
43:
44:
45:
46:
47: 48: 49:
50: public function macroLabel(NMacroNode $node, $writer)
51: {
52: $cmd = 'if ($_label = $form[%node.word]->getLabel()) echo $_label->addAttributes(%node.array)';
53: if ($node->isEmpty = (substr($node->args, -1) === '/')) {
54: $node->setArgs(substr($node->args, 0, -1));
55: return $writer->write($cmd);
56: } else {
57: return $writer->write($cmd . '->startTag()');
58: }
59: }
60:
61: }
62: