12
12
namespace Symfony \Bridge \Twig \Extension ;
13
13
14
14
use Symfony \Bridge \Twig \TokenParser \FormThemeTokenParser ;
15
- use Symfony \Component \Form \TemplateContext ;
15
+ use Symfony \Component \Form \FormView ;
16
16
use Symfony \Component \Form \Exception \FormException ;
17
17
18
18
/**
@@ -43,14 +43,14 @@ public function initRuntime(\Twig_Environment $environment)
43
43
}
44
44
45
45
/**
46
- * Sets a theme for a given context .
46
+ * Sets a theme for a given view .
47
47
*
48
- * @param TemplateContext $context A TemplateContext instance
48
+ * @param FormView $view A FormView instance
49
49
* @param array $resources An array of resources
50
50
*/
51
- public function setTheme (TemplateContext $ context , array $ resources )
51
+ public function setTheme (FormView $ view , array $ resources )
52
52
{
53
- $ this ->themes ->attach ($ context , $ resources );
53
+ $ this ->themes ->attach ($ view , $ resources );
54
54
}
55
55
56
56
/**
@@ -86,115 +86,115 @@ public function getFunctions()
86
86
*
87
87
* <form action="..." method="post" {{ form_enctype(form) }}>
88
88
*
89
- * @param TemplateContext $context The context for which to render the encoding type
89
+ * @param FormView $view The view for which to render the encoding type
90
90
*/
91
- public function renderEnctype (TemplateContext $ context )
91
+ public function renderEnctype (FormView $ view )
92
92
{
93
- return $ this ->render ($ context , 'enctype ' );
93
+ return $ this ->render ($ view , 'enctype ' );
94
94
}
95
95
96
96
/**
97
- * Renders a row for the context .
97
+ * Renders a row for the view .
98
98
*
99
- * @param TemplateContext $context The context to render as a row
99
+ * @param FormView $view The view to render as a row
100
100
*/
101
- public function renderRow (TemplateContext $ context , array $ variables = array ())
101
+ public function renderRow (FormView $ view , array $ variables = array ())
102
102
{
103
- return $ this ->render ($ context , 'row ' , $ variables );
103
+ return $ this ->render ($ view , 'row ' , $ variables );
104
104
}
105
105
106
- public function renderRest (TemplateContext $ context , array $ variables = array ())
106
+ public function renderRest (FormView $ view , array $ variables = array ())
107
107
{
108
- return $ this ->render ($ context , 'rest ' , $ variables );
108
+ return $ this ->render ($ view , 'rest ' , $ variables );
109
109
}
110
110
111
111
/**
112
- * Renders the HTML for a given context
112
+ * Renders the HTML for a given view
113
113
*
114
114
* Example usage in Twig:
115
115
*
116
- * {{ form_widget(context ) }}
116
+ * {{ form_widget(view ) }}
117
117
*
118
118
* You can pass attributes element during the call:
119
119
*
120
- * {{ form_widget(context , {'class': 'foo'}) }}
120
+ * {{ form_widget(view , {'class': 'foo'}) }}
121
121
*
122
122
* Some fields also accept additional variables as parameters:
123
123
*
124
- * {{ form_widget(context , {}, {'separator': '+++++'}) }}
124
+ * {{ form_widget(view , {}, {'separator': '+++++'}) }}
125
125
*
126
- * @param TemplateContext $context The context to render
126
+ * @param FormView $view The view to render
127
127
* @param array $attributes HTML attributes passed to the template
128
128
* @param array $parameters Additional variables passed to the template
129
129
* @param array|string $resources A resource or array of resources
130
130
*/
131
- public function renderWidget (TemplateContext $ context , array $ variables = array (), $ resources = null )
131
+ public function renderWidget (FormView $ view , array $ variables = array (), $ resources = null )
132
132
{
133
133
if (null !== $ resources && !is_array ($ resources )) {
134
134
$ resources = array ($ resources );
135
135
}
136
136
137
- return $ this ->render ($ context , 'widget ' , $ variables , $ resources );
137
+ return $ this ->render ($ view , 'widget ' , $ variables , $ resources );
138
138
}
139
139
140
140
/**
141
- * Renders the errors of the given context
141
+ * Renders the errors of the given view
142
142
*
143
- * @param TemplateContext $context The context to render the errors for
143
+ * @param FormView $view The view to render the errors for
144
144
* @param array $params Additional variables passed to the template
145
145
*/
146
- public function renderErrors (TemplateContext $ context )
146
+ public function renderErrors (FormView $ view )
147
147
{
148
- return $ this ->render ($ context , 'errors ' );
148
+ return $ this ->render ($ view , 'errors ' );
149
149
}
150
150
151
151
/**
152
- * Renders the label of the given context
152
+ * Renders the label of the given view
153
153
*
154
- * @param TemplateContext $context The context to render the label for
154
+ * @param FormView $view The view to render the label for
155
155
*/
156
- public function renderLabel (TemplateContext $ context , $ label = null )
156
+ public function renderLabel (FormView $ view , $ label = null )
157
157
{
158
- return $ this ->render ($ context , 'label ' , null === $ label ? array () : array ('label ' => $ label ));
158
+ return $ this ->render ($ view , 'label ' , null === $ label ? array () : array ('label ' => $ label ));
159
159
}
160
160
161
161
/**
162
- * Renders the widget data of the given context
162
+ * Renders the widget data of the given view
163
163
*
164
- * @param TemplateContext $context The context to render the data for
164
+ * @param FormView $view The view to render the data for
165
165
*/
166
- public function renderData (TemplateContext $ context )
166
+ public function renderData (FormView $ view )
167
167
{
168
168
return $ form ->getData ();
169
169
}
170
170
171
- protected function render (TemplateContext $ context , $ section , array $ variables = array (), array $ resources = null )
171
+ protected function render (FormView $ view , $ section , array $ variables = array (), array $ resources = null )
172
172
{
173
- $ templates = $ this ->getTemplates ($ context , $ resources );
174
- $ blocks = $ context ->getVar ('types ' );
173
+ $ templates = $ this ->getTemplates ($ view , $ resources );
174
+ $ blocks = $ view ->getVar ('types ' );
175
175
foreach ($ blocks as &$ block ) {
176
176
$ block = $ block .'__ ' .$ section ;
177
177
178
178
if (isset ($ templates [$ block ])) {
179
179
if ('widget ' === $ section || 'row ' === $ section ) {
180
- $ context ->setRendered (true );
180
+ $ view ->setRendered (true );
181
181
}
182
182
183
- return $ templates [$ block ]->renderBlock ($ block , array_merge ($ context ->getVars (), $ variables ));
183
+ return $ templates [$ block ]->renderBlock ($ block , array_merge ($ view ->getVars (), $ variables ));
184
184
}
185
185
}
186
186
187
187
throw new FormException (sprintf ('Unable to render form as none of the following blocks exist: "%s". ' , implode ('", " ' , $ blocks )));
188
188
}
189
189
190
- protected function getTemplate (TemplateContext $ context , $ name , array $ resources = null )
190
+ protected function getTemplate (FormView $ view , $ name , array $ resources = null )
191
191
{
192
- $ templates = $ this ->getTemplates ($ context , $ resources );
192
+ $ templates = $ this ->getTemplates ($ view , $ resources );
193
193
194
194
return $ templates [$ name ];
195
195
}
196
196
197
- protected function getTemplates (TemplateContext $ context , array $ resources = null )
197
+ protected function getTemplates (FormView $ view , array $ resources = null )
198
198
{
199
199
// templates are looked for in the following resources:
200
200
// * resources provided directly into the function call
@@ -205,7 +205,7 @@ protected function getTemplates(TemplateContext $context, array $resources = nul
205
205
$ all = $ this ->resources ;
206
206
207
207
// themes
208
- $ parent = $ context ;
208
+ $ parent = $ view ;
209
209
do {
210
210
if (isset ($ this ->themes [$ parent ])) {
211
211
$ all = array_merge ($ all , $ this ->themes [$ parent ]);
0 commit comments