1 | <?php |
||
2 | |||
3 | namespace Frontend\Core\Engine; |
||
4 | |||
5 | /** |
||
6 | * Twig node for writing out the compiled representation of an opeing form tag. |
||
7 | */ |
||
8 | class FormNode extends \Twig_Node |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
9 | { |
||
10 | /** |
||
11 | * @var string Template variable holding the form. |
||
12 | */ |
||
13 | private $form; |
||
14 | |||
15 | /** |
||
16 | * @param string $form The name of the template variable to which the form is assigned |
||
17 | * @param int $lineNumber |
||
18 | * @param string $tag |
||
19 | */ |
||
20 | public function __construct(string $form, int $lineNumber, string $tag) |
||
21 | { |
||
22 | parent::__construct([], [], $lineNumber, $tag); |
||
23 | $this->form = $form; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param \Twig_Compiler $compiler |
||
28 | */ |
||
29 | public function compile(\Twig_Compiler $compiler): void |
||
30 | { |
||
31 | // Set some string representations to make the code writing via the |
||
32 | // compiler a bit more readable. ("a bit") |
||
33 | $form = "\$context['form_{$this->form}']"; |
||
34 | $formAction = $form . '->getAction()'; |
||
35 | $formMethod = $form . '->getMethod()'; |
||
36 | $formName = $form . '->getName()'; |
||
37 | $formToken = $form . '->getToken()'; |
||
38 | $formUseToken = $form . '->getUseToken()'; |
||
39 | $formParamsHtml = $form . '->getParametersHTML()'; |
||
40 | $formAttrAction = ' action="\', ' . $formAction . ', \'"'; |
||
41 | $formAttrMethod = ' method="\', ' . $formMethod . ', \'"'; |
||
42 | $hiddenFormName = '<input type="hidden" name="form" value="\', ' . $formName . ', \'" id="form\', ucfirst(' . $formName . '), \'" />'; |
||
43 | $hiddenFormToken = '<input type="hidden" name="form_token" value="\', ' . $formToken . ', \'" id="formToken\', ucfirst(' . $formName . '), \'" />'; |
||
44 | |||
45 | $compiler |
||
46 | ->addDebugInfo($this) |
||
47 | |||
48 | ->write('echo \'<form') |
||
49 | ->raw($formAttrMethod) |
||
50 | ->raw($formAttrAction) |
||
51 | ->raw("', ") |
||
52 | ->raw(' ' . $formParamsHtml) |
||
53 | ->raw(', \'') |
||
54 | ->raw('>\'') |
||
55 | ->raw(";\n") |
||
56 | |||
57 | ->write("echo '$hiddenFormName';\n") |
||
58 | ->write("if($formUseToken) echo '$hiddenFormToken';") |
||
59 | ; |
||
60 | } |
||
61 | } |
||
62 |