1010namespace Nette \Bridges \FormsLatte ;
1111
1212use Nette ;
13+ use Nette \Forms \Container ;
1314use Nette \Forms \Form ;
1415use Nette \Utils \Html ;
1516
2021 */
2122class Runtime
2223{
23- use Nette \StaticClass;
24-
25- public static function initializeForm (Form $ form ): void
26- {
27- $ form ->fireRenderEvents ();
28- foreach ($ form ->getControls () as $ control ) {
29- $ control ->setOption ('rendered ' , false );
30- }
31- }
24+ /** @var Container[] */
25+ private array $ stack = [];
3226
3327
3428 /**
3529 * Renders form begin.
3630 */
37- public static function renderFormBegin (Form $ form , array $ attrs , bool $ withTags = true ): string
31+ public function renderFormBegin (array $ attrs , bool $ withTags = true ): string
3832 {
33+ $ form = $ this ->current ();
3934 $ el = $ form ->getElementPrototype ();
4035 $ el ->action = (string ) $ el ->action ;
4136 $ el = clone $ el ;
@@ -51,8 +46,9 @@ public static function renderFormBegin(Form $form, array $attrs, bool $withTags
5146 /**
5247 * Renders form end.
5348 */
54- public static function renderFormEnd (Form $ form , bool $ withTags = true ): string
49+ public function renderFormEnd (bool $ withTags = true ): string
5550 {
51+ $ form = $ this ->current ();
5652 $ s = '' ;
5753 if ($ form ->isMethod ('get ' )) {
5854 foreach (preg_split ('#[;&]# ' , (string ) parse_url ($ form ->getElementPrototype ()->action , PHP_URL_QUERY ), -1 , PREG_SPLIT_NO_EMPTY ) as $ param ) {
@@ -75,12 +71,35 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
7571 }
7672
7773
78- public static function item ($ item, $ global ): object
74+ public function item ($ item ): object
7975 {
80- if (is_object ($ item )) {
81- return $ item ;
76+ return is_object ($ item )
77+ ? $ item
78+ : $ this ->current ()[$ item ];
79+ }
80+
81+
82+ public function begin (Container $ form ): void
83+ {
84+ $ this ->stack [] = $ form ;
85+
86+ if ($ form instanceof Form) {
87+ $ form ->fireRenderEvents ();
88+ foreach ($ form ->getControls () as $ control ) {
89+ $ control ->setOption ('rendered ' , false );
90+ }
8291 }
83- $ form = end ($ global ->formsStack ) ?: throw new \LogicException ('Form declaration is missing, did you use {form} or <form n:name> tag? ' );
84- return $ form [$ item ];
92+ }
93+
94+
95+ public function end (): void
96+ {
97+ array_pop ($ this ->stack );
98+ }
99+
100+
101+ public function current (): Container
102+ {
103+ return end ($ this ->stack ) ?: throw new \LogicException ('Form declaration is missing, did you use {form} or <form n:name> tag? ' );
85104 }
86105}
0 commit comments