public function _field(HtmlNode $node, TemplateNode $value) { $internal = new InternalNode(); foreach ($node->getChildren() as $child) { $internal->append($child->detach()); } $start = '$field = $Form->field(' . PhpNode::expr($value)->code . ', '; $start .= PhpNode::attributes($node)->code . ')'; $internal->prepend(new PhpNode($start, true)); $internal->append(new PhpNode('$field->end()')); $node->replaceWith($internal); }
/** * Translates content of node, automatically replaces expressions with placeholders. * Expects content of node to be plural and macro parameter to be singular. * @param HtmlNode $node Node. * @param TemplateNode|null $value Macro parameter. */ public function _tn(HtmlNode $node, TemplateNode $value) { $translate = ''; $num = 1; $params = array(); $before = array(); foreach ($node->getChildren() as $child) { if ($child instanceof TextNode) { $translate .= $child->text; } else { if ($child instanceof PhpNode and !$child->statement) { $translate .= '%' . $num; $params[] = $child->code; $num++; } else { $translate .= '%' . $num; $params[] = PhpNode::expr($child); $num++; } } } if (count($params) == 0) { $params = ''; } else { $params = ', ' . implode(', ', $params); } $translate = trim($translate); $node->clear(); $phpNode = new PhpNode('tn(' . var_export($translate, true) . ', ' . PhpNode::expr($value)->code . $params . ')'); $node->append($phpNode); }