1 | <?php |
||
2 | |||
3 | namespace Frontend\Core\Engine; |
||
4 | |||
5 | /** |
||
6 | * Twig note for writing out the compiled version of a form field error. |
||
7 | */ |
||
8 | class FormFieldErrorNode extends \Twig_Node |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | private $form; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $field; |
||
19 | |||
20 | /** |
||
21 | * @param string $form Name of the template var holding the form this field |
||
22 | * error belongs to. |
||
23 | * @param string $field Name of the field of which we need to render the error. |
||
24 | * @param int $lineNumber Line number in the template source file. |
||
25 | * @param string $tag the name of the template tag. |
||
26 | */ |
||
27 | public function __construct(string $form, string $field, int $lineNumber, string $tag) |
||
28 | { |
||
29 | parent::__construct([], [], $lineNumber, $tag); |
||
30 | $this->form = $form; |
||
31 | $this->field = $field; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param \Twig_Compiler $compiler |
||
36 | */ |
||
37 | public function compile(\Twig_Compiler $compiler): void |
||
38 | { |
||
39 | $writeErrorMessage = 'echo ' |
||
40 | . "\$context['form_{$this->form}']->getField('{$this->field}')->getErrors() " |
||
41 | . "? '<span class=\"formError\">' " |
||
42 | . ". \$context['form_{$this->form}']->getField('{$this->field}')->getErrors() " |
||
43 | . ". '</span>' : '';"; |
||
44 | $compiler |
||
45 | ->addDebugInfo($this) |
||
46 | ->write($writeErrorMessage) |
||
47 | ; |
||
48 | } |
||
49 | } |
||
50 |