8000 [Form] Inverted the logic of "single_control" and renamed it to "comp… · symfony/symfony@2e6cdd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e6cdd1

Browse files
committed
[Form] Inverted the logic of "single_control" and renamed it to "compound". The opposite is now "simple".
1 parent 98a7c0c commit 2e6cdd1

Some content is hidden

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

44 files changed

+121
-120
lines changed

UPGRADE-2.1.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
themes.
311311
312312
The "field_widget" and all references to it should be renamed to
313-
"form_widget_single_control":
313+
"form_widget_simple":
314314
315315
Before:
316316
@@ -329,15 +329,15 @@
329329
{% block url_widget %}
330330
{% spaceless %}
331331
{% set type = type|default('url') %}
332-
{{ block('form_widget_single_control') }}
332+
{{ block('form_widget_simple') }}
333333
{% endspaceless %}
334334
{% endblock url_widget %}
335335
```
336336
337337
All other "field_*" blocks and references to them should be renamed to
338338
"form_*". If you previously defined both a "field_*" and a "form_*"
339339
block, you can merge them into a single "form_*" block and check the new
340-
Boolean variable "single_control":
340+
Boolean variable "compound":
341341
342342
Before:
343343
@@ -360,10 +360,10 @@
360360
```
361361
{% block form_errors %}
362362
{% spaceless %}
363-
{% if single_control %}
364-
... field code ...
365-
{% else %}
363+
{% if compound %}
366364
... form code ...
365+
{% else %}
366+
... field code ...
367367
{% endif %}
368368
{% endspaceless %}
369369
{% endblock form_errors %}
@@ -487,7 +487,7 @@
487487
You can access all other methods on the `FormConfigInterface` object instead.
488488
489489
Instead of `getChildren` and `hasChildren`, you should now use `all` and
490-
`count` instead.
490+
`count`.
491491
492492
Before:
493493
@@ -609,7 +609,7 @@
609609
610610
* No options are passed to `getParent()` of `FormTypeInterface` anymore. If
611611
you previously dynamically inherited from FormType or FieldType, you can now
612-
dynamically set the "single_control" option instead.
612+
dynamically set the "compound" option instead.
613613
614614
Before:
615615
@@ -625,12 +625,12 @@
625625
```
626626
public function setDefaultOptions(OptionsResolverInterface $resolver)
627627
{
628-
$singleControl = function (Options $options) {
629-
return !$options['expanded'];
628+
$compound = function (Options $options) {
629+
return $options['expanded'];
630630
};
631631
632632
$resolver->setDefaults(array(
633-
'single_control' => $singleControl,
633+
'compound' => $compound,
634634
));
635635
}
636636

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
{% block form_widget %}
44
{% spaceless %}
5-
{% if single_control %}
6-
{{ block('form_widget_single_control') }}
7-
{% else %}
5+
{% if compound %}
86
{{ block('form_widget_compound') }}
7+
{% else %}
8+
{{ block('form_widget_simple') }}
99
{% endif %}
1010
{% endspaceless %}
1111
{% endblock form_widget %}
1212

13-
{% block form_widget_single_control %}
13+
{% block form_widget_simple %}
1414
{% spaceless %}
1515
{% set type = type|default('text') %}
1616
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
1717
{% endspaceless %}
18-
{% endblock form_widget_single_control %}
18+
{% endblock form_widget_simple %}
1919

2020
{% block form_widget_compound %}
2121
{% spaceless %}
@@ -112,7 +112,7 @@
112112
{% block datetime_widget %}
113113
{% spaceless %}
114114
{% if widget == 'single_text' %}
115-
{{ block('form_widget_single_control') }}
115+
{{ block('form_widget_simple') }}
116116
{% else %}
117117
<div {{ block('widget_container_attributes') }}>
118118
{{ form_errors(form.date) }}
@@ -127,7 +127,7 @@
127127
{% block date_widget %}
128128
{% spaceless %}
129129
{% if widget == 'single_text' %}
130-
{{ block('form_widget_single_control') }}
130+
{{ block('form_widget_simple') }}
131131
{% else %}
132132
<div {{ block('widget_container_attributes') }}>
133133
{{ date_pattern|replace({
@@ -143,7 +143,7 @@
143143
{% block time_widget %}
144144
{% spaceless %}
145145
{% if widget == 'single_text' %}
146-
{{ block('form_widget_single_control') }}
146+
{{ block('form_widget_simple') }}
147147
{% else %}
148148
<div {{ block('widget_container_attributes') }}>
149149
{{ form_widget(form.hour, { 'attr': { 'size': '1' } }) }}:{{ form_widget(form.minute, { 'attr': { 'size': '1' } }) }}{% if with_seconds %}:{{ form_widget(form.second, { 'attr': { 'size': '1' } }) }}{% endif %}
@@ -156,70 +156,70 @@
156156
{% spaceless %}
157157
{# type="number" doesn't work with floats #}
158158
{% set type = type|default('text') %}
159-
{{ block('form_widget_single_control') }}
159+
{{ block('form_widget_simple') }}
160160
{% endspaceless %}
161161
{% endblock number_widget %}
162162

163163
{% block integer_widget %}
164164
{% spaceless %}
165165
{% set type = type|default('number') %}
166-
{{ block('form_widget_single_control') }}
166+
{{ block('form_widget_simple') }}
167167
{% endspaceless %}
168168
{% endblock integer_widget %}
169169

170170
{% block money_widget %}
171171
{% spaceless %}
172-
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_single_control') })|raw }}
172+
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
173173
{% endspaceless %}
174174
{% endblock money_widget %}
175175

176176
{% block url_widget %}
177177
{% spaceless %}
178178
{% set type = type|default('url') %}
179-
{{ block('form_widget_single_control') }}
179+
{{ block('form_widget_simple') }}
180180
{% endspaceless %}
181181
{% endblock url_widget %}
182182

183183
{% block search_widget %}
184184
{% spaceless %}
185185
{% set type = type|default('search') %}
186-
{{ block('form_widget_single_control') }}
186+
{{ block('form_widget_simple') }}
187187
{% endspaceless %}
188188
{% endblock search_widget %}
189189

190190
{% block percent_widget %}
191191
{% spaceless %}
192192
{% set type = type|default('text') %}
193-
{{ block(' 10000 form_widget_single_control') }} %
193+
{{ block('form_widget_simple') }} %
194194
{% endspaceless %}
195195
{% endblock percent_widget %}
196196

197197
{% block password_widget %}
198198
{% spaceless %}
199199
{% set type = type|default('password') %}
200-
{{ block('form_widget_single_control') }}
200+
{{ block('form_widget_simple') }}
201201
{% endspaceless %}
202202
{% endblock password_widget %}
203203

204204
{% block hidden_widget %}
205205
{% spaceless %}
206206
{% set type = type|default('hidden') %}
207-
{{ block('form_widget_single_control') }}
207+
{{ block('form_widget_simple') }}
208208
{% endspaceless %}
209209
{% endblock hidden_widget %}
210210

211211
{% block email_widget %}
212212
{% spaceless %}
213213
{% set type = type|default('email') %}
214-
{{ block('form_widget_single_control') }}
214+
{{ block('form_widget_simple') }}
215215
{% endspaceless %}
216216
{% endblock email_widget %}
217217

218218
{# Labels #}
219219

220220
{% block form_label %}
221221
{% spaceless %}
222-
{% if single_control %}
222+
{% if not compound %}
223223
{% set label_attr = label_attr|merge({'for': id}) %}
224224
{% endif %}
225225
{% if required %}
@@ -245,7 +245,7 @@
245245
If the child is a compound form, the errors are rendered inside
246246
the container. See also block form_rows.
247247
#}
248-
{% if single_control %}
248+
{% if not compound %}
249249
{{ form_errors(form) }}
250250
{% endif %}
251251
{{ form_widget(form) }}
@@ -320,7 +320,7 @@
320320

321321
{% block generic_label %}{{ block('form_label') }}{% endblock %}
322322
{% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %}
323-
{% block field_widget %}{{ block('form_widget_single_control') }}{% endblock %}
323+
{% block field_widget %}{{ block('form_widget_simple') }}{% endblock %}
324324
{% block field_label %}{{ block('form_label') }}{% endblock %}
325325
{% block field_row %}{{ block('form_row') }}{% endblock %}
326326
{% block field_enctype %}{{ block('form_enctype') }}{% endblock %}

src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{ form_label(form, label|default(null)) }}
88
</td>
99
<td>
10-
{% if single_control %}
10+
{% if not compound %}
1111
{{ form_errors(form) }}
1212
{% endif %}
1313
{{ form_widget(form) }}
@@ -18,7 +18,7 @@
1818

1919
{% block form_errors %}
2020
{% spaceless %}
21-
{% if single_control %}
21+
{% if not compound %}
2222
{{ parent() }}
2323
{% else %}
2424
{% if errors|length > 0 %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{% block form_widget_single_control %}
1+
{% block form_widget_simple %}
22
{% spaceless %}
33
{% set type = type|default('text') %}
44
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
55
{% endspaceless %}
6-
{% endblock form_widget_single_control %}
6+
{% endblock form_widget_simple %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% extends 'form_div_layout.html.twig' %}
22

3-
{% block form_widget_single_control %}
3+
{% block form_widget_simple %}
44
{% spaceless %}
55
{% set type = type|default('text') %}
66
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
77
{% endspaceless %}
8-
{% endblock form_widget_single_control %}
8+
{% endblock form_widget_simple %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% use 'form_div_layout.html.twig' %}
22

3-
{% block form_widget_single_control %}
3+
{% block form_widget_simple %}
44
{% spaceless %}
55
{% set type = type|default('text') %}
66
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
77
{% endspaceless %}
8-
{% endblock form_widget_single_control %}
8+
{% endblock form_widget_simple %}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php if ($widget == 'single_text'): ?>
2-
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
2+
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
33
<?php else: ?>
44
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
55
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php if ($widget == 'single_text'): ?>
2-
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
2+
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
33
<?php else: ?>
44
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
55
<?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : 'email')) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control') ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple') ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
2-
<?php if ($single_control) { $label_attr['for'] = $id; } ?>
2+
<?php if (!$compound) { $label_attr['for'] = $id; } ?>
33
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div>
22
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
3-
<?php if ($single_control): ?>
3+
<?php if (!$compound): ?>
44
<?php echo $view['form']->errors($form) ?>
55
<?php endif ?>
66
<?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 if ($single_control): ?>
2-
<?php echo $view['form']->renderBlock('form_widget_single_control')?>
3-
<?php else: ?>
1+
<?php if ($compound): ?>
42
<?php echo $view['form']->renderBlock('form_widget_compound')?>
3+
<?php else: ?>
4+
<?php echo $view['form']->renderBlock('form_widget_simple')?>
55
<?php endif ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "hidden")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "number")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_single_control'), $money_pattern) ?>
1+
<?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_simple'), $money_pattern) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "password")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "password")) ?>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?> %
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> %
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "search")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "search")) ?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php if ($widget == 'single_text'): ?>
2-
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
2+
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
33
<?php else: ?>
44
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
55
<?php
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "url")) ?>
1+
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "url")) ?>

src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_errors.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php if ($single_control): ?>
1+
<?php if (!$compound): ?>
22
<?php if ($errors): ?>
33
<ul>
44
<?php foreach ($errors as $error): ?>

src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_row.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
44
</td>
55
<td>
6-
<?php if ($single_control): ?>
6+
<?php if (!$compound): ?>
77
<?php echo $view['form']->errors($form) ?>
88
<?php endif ?>
99
<?php echo $view['form']->widget($form) ?>

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ CHANGELOG
5555
by event subscribers
5656
* simplified CSRF protection and removed the csrf type
5757
* deprecated FieldType and merged it into FormType
58+
* added new option "compound" that lets you switch between field and form behavior
5859
* [BC BREAK] renamed theme blocks
5960
* "field_*" to "form_*"
60-
* "field_widget" to "form_widget_single_control"
61+
* "field_widget" to "form_widget_simple"
6162
* "widget_choice_options" to "choice_widget_options"
6263
* "generic_label" to "form_label"
6364
* added theme blocks "form_widget_compound", "choice_widget_expanded" and

src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
5151
};
5252

5353
$resolver->setDefaults(array(
54-
'value' => '1',
55-
'empty_data' => $emptyData,
56-
'single_control' => true,
54+
'value' => '1',
55+
'empty_data' => $emptyData,
56+
'compound' => false,
5757
));
5858
}
5959

0 commit comments

Comments
 (0)
0