8000 [Form] Renamed TemplateContext to FormView · ivanrey/symfony@72b17cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 72b17cd

Browse files
committed
[Form] Renamed TemplateContext to FormView
1 parent ca6ae09 commit 72b17cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+410
-410
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
15-
use Symfony\Component\Form\TemplateContext;
15+
use Symfony\Component\Form\FormView;
1616
use Symfony\Component\Form\Exception\FormException;
1717

1818
/**
@@ -43,14 +43,14 @@ public function initRuntime(\Twig_Environment $environment)
4343
}
4444

4545
/**
46-
* Sets a theme for a given context.
46+
* Sets a theme for a given view.
4747
*
48-
* @param TemplateContext $context A TemplateContext instance
48+
* @param FormView $view A FormView instance
4949
* @param array $resources An array of resources
5050
*/
51-
public function setTheme(TemplateContext $context, array $resources)
51+
public function setTheme(FormView $view, array $resources)
5252
{
53-
$this->themes->attach($context, $resources);
53+
$this->themes->attach($view, $resources);
5454
}
5555

5656
/**
@@ -86,115 +86,115 @@ public function getFunctions()
8686
*
8787
* <form action="..." method="post" {{ form_enctype(form) }}>
8888
*
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
9090
*/
91-
public function renderEnctype(TemplateContext $context)
91+
public function renderEnctype(FormView $view)
9292
{
93-
return $this->render($context, 'enctype');
93+
return $this->render($view, 'enctype');
9494
}
9595

9696
/**
97-
* Renders a row for the context.
97+
* Renders a row for the view.
9898
*
99-
* @param TemplateContext $context The context to render as a row
99+
* @param FormView $view The view to render as a row
100100
*/
101-
public function renderRow(TemplateContext $context, array $variables = array())
101+
public function renderRow(FormView $view, array $variables = array())
102102
{
103-
return $this->render($context, 'row', $variables);
103+
return $this->render($view, 'row', $variables);
104104
}
105105

106-
public function renderRest(TemplateContext $context, array $variables = array())
106+
public function renderRest(FormView $view, array $variables = array())
107107
{
108-
return $this->render($context, 'rest', $variables);
108+
return $this->render($view, 'rest', $variables);
109109
}
110110

111111
/**
112-
* Renders the HTML for a given context
112+
* Renders the HTML for a given view
113113
*
114114
* Example usage in Twig:
115115
*
116-
* {{ form_widget(context) }}
116+
* {{ form_widget(view) }}
117117
*
118118
* You can pass attributes element during the call:
119119
*
120-
* {{ form_widget(context, {'class': 'foo'}) }}
120+
* {{ form_widget(view, {'class': 'foo'}) }}
121121
*
122122
* Some fields also accept additional variables as parameters:
123123
*
124-
* {{ form_widget(context, {}, {'separator': '+++++'}) }}
124+
* {{ form_widget(view, {}, {'separator': '+++++'}) }}
125125
*
126-
* @param TemplateContext $context The context to render
126+
* @param FormView $view The view to render
127127
* @param array $attributes HTML attributes passed to the template
128128
* @param array $parameters Additional variables passed to the template
129129
* @param array|string $resources A resource or array of resources
130130
*/
131-
public function renderWidget(TemplateContext $context, array $variables = array(), $resources = null)
131+
public function renderWidget(FormView $view, array $variables = array(), $resources = null)
132132
{
133133
if (null !== $resources && !is_array($resources)) {
134134
$resources = array($resources);
135135
}
136136

137-
return $this->render($context, 'widget', $variables, $resources);
137+
return $this->render($view, 'widget', $variables, $resources);
138138
}
139139

140140
/**
141-
* Renders the errors of the given context
141+
* Renders the errors of the given view
142142
*
143-
* @param TemplateContext $context The context to render the errors for
143+
* @param FormView $view The view to render the errors for
144144
* @param array $params Additional variables passed to the template
145145
*/
146-
public function renderErrors(TemplateContext $context)
146+
public function renderErrors(FormView $view)
147147
{
148-
return $this->render($context, 'errors');
148+
return $this->render($view, 'errors');
149149
}
150150

151151
/**
152-
* Renders the label of the given context
152+
* Renders the label of the given view
153153
*
154-
* @param TemplateContext $context The context to render the label for
154+
* @param FormView $view The view to render the label for
155155
*/
156-
public function renderLabel(TemplateContext $context, $label = null)
156+
public function renderLabel(FormView $view, $label = null)
157157
{
158-
return $this->render($context, 'label', null === $label ? array() : array('label' => $label));
158+
return $this->render($view, 'label', null === $label ? array() : array('label' => $label));
159159
}
160160

161161
/**
162-
* Renders the widget data of the given context
162+
* Renders the widget data of the given view
163163
*
164-
* @param TemplateContext $context The context to render the data for
164+
* @param FormView $view The view to render the data for
165165
*/
166-
public function renderData(TemplateContext $context)
166+
public function renderData(FormView $view)
167167
{
168168
return $form->getData();
169169
}
170170

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)
172172
{
173-
$templates = $this->getTemplates($context, $resources);
174-
$blocks = $context->getVar('types');
173+
$templates = $this->getTemplates($view, $resources);
174+
$blocks = $view->getVar('types');
175175
foreach ($blocks as &$block) {
176176
$block = $block.'__'.$section;
177177

178178
if (isset($templates[$block])) {
179179
if ('widget' === $section || 'row' === $section) {
180-
$context->setRendered(true);
180+
$view->setRendered(true);
181181
}
182182

183-
return $templates[$block]->renderBlock($block, array_merge($context->getVars(), $variables));
183+
return $templates[$block]->renderBlock($block, array_merge($view->getVars(), $variables));
184184
}
185185
}
186186

187187
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
188188
}
189189

190-
protected function getTemplate(TemplateContext $context, $name, array $resources = null)
190+
protected function getTemplate(FormView $view, $name, array $resources = null)
191191
{
192-
$templates = $this->getTemplates($context, $resources);
192+
$templates = $this->getTemplates($view, $resources);
193193

194194
return $templates[$name];
195195
}
196196

197-
protected function getTemplates(TemplateContext $context, array $resources = null)
197+
protected function getTemplates(FormView $view, array $resources = null)
198198
{
199199
// templates are looked for in the following resources:
200200
// * resources provided directly into the function call
@@ -205,7 +205,7 @@ protected function getTemplates(TemplateContext $context, array $resources = nul
205205
$all = $this->resources;
206206

207207
// themes
208-
$parent = $context;
208+
$parent = $view;
209209
do {
210210
if (isset($this->themes[$parent])) {
211211
$all = array_merge($all, $this->themes[$parent]);

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget.html.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php if ($expanded): ?>
22
<div<?php echo $view['form']->attributes() ?>>
3-
<?php foreach ($context as $choice => $child): ?>
3+
<?php foreach ($form as $choice => $child): ?>
44
<?php echo $view['form']->widget($child) ?>
55
<?php echo $view['form']->label($child) ?>
66
<?php endforeach ?>
@@ -16,27 +16,27 @@
1616
<?php if (!$multiple && !$required): ?><option value=""><?php echo $empty_value; ?></option><?php endif; ?>
1717
<?php if (count($preferred_choices) > 0): ?>
1818
<?php foreach ($preferred_choices as $choice => $label): ?>
19-
<?php if ($context->isChoiceGroup($label)): ?>
19+
<?php if ($form->isChoiceGroup($label)): ?>
2020
<optgroup label="<?php echo $choice ?>">
2121
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
22-
<option value="<?php echo $nestedChoice ?>"<?php if ($context->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
22+
<option value="<?php echo $nestedChoice ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
2323
<?php endforeach ?>
2424
</optgroup>
2525
<?php else: ?>
26-
<option value="<?php echo $choice ?>"<?php if ($context->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
26+
<option value="<?php echo $choice ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
2727
<?php endif ?>
2828
<?php endforeach ?>
2929
<option disabled="disabled"><?php echo $separator ?></option>
3030
<?php endif ?>
3131
<?php foreach ($choices as $choice => $label): ?>
32-
<?php if ($context->isChoiceGroup($label)): ?>
32+
<?php if ($form->isChoiceGroup($label)): ?>
3333
<optgroup label="<?php echo $choice ?>">
3434
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
35-
<option value="<?php echo $nestedChoice ?>"<?php if ($context->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
35+
<option value="<?php echo $nestedChoice ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
3636
<?php endforeach ?>
3737
</optgroup>
3838
<?php else: ?>
39-
<option value="<?php echo $choice ?>"<?php if ($context->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
39+
<option value="<?php echo $choice ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
4040
<?php endif ?>
4141
<?php endforeach ?>
4242
</select>

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<?php else: ?>
1212
<div<?php echo $view['form']->attributes() ?>>
1313
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
14-
$view['form']->widget($context['year']),
15-
$view['form']->widget($context['month']),
16-
$view['form']->widget($context['day']),
14+
$view['form']->widget($form['year']),
15+
$view['form']->widget($form['month']),
16+
$view['form']->widget($form['day']),
1717
), $date_pattern) ?>
1818
</div>
1919
<?php endif ?>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div<?php echo $view['form']->attributes() ?>>
2-
<?php echo $view['form']->widget($context['date'])
2+
<?php echo $view['form']->widget($form['date'])
33
. ' '
4-
. $view['form']->widget($context['time']) ?>
4+
. $view['form']->widget($form['time']) ?>
55
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php if ($context->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
1+
<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php foreach ($context->getChildren() as $context): ?>
2-
<?php if (!$context->isRendered()): ?>
3-
<?php echo $view['form']->row($context) ?>
1+
<?php foreach ($form->getChildren() as $child): ?>
2+
<?php if (!$child->isRendered()): ?>
3+
<?php echo $view['form']->row($child) ?>
44
<?php endif; ?>
55
<?php endforeach; ?>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<?php echo $view['form']->label($context) ?>
3-
<?php echo $view['form']->errors($context) ?>
4-
<?php echo $view['form']->widget($context) ?>
2+
<?php echo $view['form']->label($form) ?>
3+
<?php echo $view['form']->errors($form) ?>
4+
<?php echo $view['form']->widget($form) ?>
55
</div>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div<?php echo $view['form']->attributes() ?>>
22
<input type="file"
3-
id="<?php echo $context['file']->getVar('id') ?>"
4-
name="<?php echo $context['file']->getVar('name') ?>"
5-
<?php if ($context['file']->getVar('disabled')): ?>disabled="disabled"<?php endif ?>
6-
<?php if ($context['file']->getVar('required')): ?>required="required"<?php endif ?>
7-
<?php if ($context['file']->getVar('class')): ?>class="<?php echo $context['file']->getVar('class') ?>"<?php endif ?>
3+
id="<?php echo $form['file']->getVar('id') ?>"
4+
name="<?php echo $form['file']->getVar('name') ?>"
5+
<?php if ($form['file']->getVar('disabled')): ?>disabled="disabled"<?php endif ?>
6+
<?php if ($form['file']->getVar('required')): ?>required="required"<?php endif ?>
7+
<?php if ($form['file']->getVar('class')): ?>class="<?php echo $form['file']->getVar('class') ?>"<?php endif ?>
88
/>
99

10-
<?php echo $view['form']->widget($context['token']) ?>
11-
<?php echo $view['form']->widget($context['name']) ?>
10+
<?php echo $view['form']->widget($form['token']) ?>
11+
<?php echo $view['form']->widget($form['name']) ?>
1212
</div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div<?php echo $view['form']->attributes() ?>>
2-
<?php echo $view['form']->errors($context); ?>
3-
<?php foreach ($context->getChildren() as $context): ?>
4-
<?php echo $view['form']->row($context); ?>
2+
<?php echo $view['form']->errors($form); ?>
3+
<?php foreach ($form->getChildren() as $child): ?>
4+
<?php echo $view['form']->row($child); ?>
55
<?php endforeach; ?>
6-
<?php echo $view['form']->rest($context) ?>
6+
<?php echo $view['form']->rest($form) ?>
77
</div>
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->widget($context) ?>
1+
<?php echo $view['form']->widget($form) ?>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php echo $view['form']->errors($context) ?>
1+
<?php echo $view['form']->errors($form) ?>
22

3-
<?php foreach ($context->getChildren() as $context): ?>
4-
<?php echo $view['form']->row($context); ?>
3+
<?php foreach ($form->getChildren() as $child): ?>
4+
<?php echo $view['form']->row($child); ?>
55
<?php endforeach; ?>

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/time_widget.html.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<?php
33
// There should be no spaces between the colons and the widgets, that's why
44
// this block is written in a single PHP tag
5-
echo $view['form']->widget($context['hour'], array('size' => 1));
5+
echo $view['form']->widget($form['hour'], array('size' => 1));
66
echo ':';
7-
echo $view['form']->widget($context['minute'], array('size' => 1));
7+
echo $view['form']->widget($form['minute'], array('size' => 1));
88

99
if ($with_seconds) {
1010
echo ':';
11-
echo $view['form']->widget($context['second'], array('size' => 1));
11+
echo $view['form']->widget($form['second'], array('size' => 1));
1212
}
1313
?>
1414
</div>

0 commit comments

Comments
 (0)
0