8000 [Form] Consolidated FormInterface, FormBuilderInterface and FormViewI… · symfony/symfony@98a7c0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 98a7c0c

Browse files
committed
[Form] Consolidated FormInterface, FormBuilderInterface and FormViewInterface
1 parent 8e128fc commit 98a7c0c

Some content is hidden

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

41 files changed

+357
-260
lines changed

UPGRADE-2.1.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,20 +468,37 @@
468468
* `getAttribute`
469469
* `hasAttribute`
470470
* `getClientData`
471+
* `getChildren`
472+
* `hasChildren`
473+
474+
Before:
475+
476+
```
477+
$form->getErrorBubbling()
478+
```
479+
480+
After:
481+
482+
```
483+
$form->getConfig()->getErrorBubbling();
484+
```
471485
472486
The method `getClientData` has a new equivalent that is named `getViewData`.
473487
You can access all other methods on the `FormConfigInterface` object instead.
474488
489+
Instead of `getChildren` and `hasChildren`, you should now use `all` and
490+
`count` instead.
491+
475492
Before:
476493
477494
```
478-
$form->getErrorBubbling()
495+
if ($form->hasChildren()) {
479496
```
480497
481498
After:
482499
483500
```
484-
$form->getConfig()->getErrorBubbling();
501+
if (count($form) > 0) {
485502
```
486503
487504
* The option "validation_constraint" is deprecated and will be removed
@@ -717,6 +734,34 @@
717734
$form = $factory->createNamed('firstName', 'text');
718735
```
719736
737+
* The methods in class `FormView` were renamed to match the naming used in
738+
`Form` and `FormBuilder`. The following list shows the old names on the
739+
left and the new names on the right:
740+
741+
* `set`: `setVar`
742+
* `has`: `hasVar`
743+
* `get`: `getVar`
744+
* `all`: `getVars`
745+
* `addChild`: `add`
746+
* `getChild`: `get`
747+
* `getChildren`: `all`
748+
* `removeChild`: `remove`
749+
* `hasChild`: `has`
750+
751+
The method `hasChildren` was deprecated. You should use `count` instead.
752+
753+
Before:
754+
755+
```
756+
$view->set('help', 'A text longer than six characters');
757+
```
758+
759+
After:
760+
761+
```
762+
$view->setVar('help', 'A text longer than six characters');
763+
```
764+
720765
### Validator
721766
722767
* The methods `setMessage()`, `getMessageTemplate()` and

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testSetDataToUninitializedEntityWithNonRequired()
115115
'property' => 'name'
116116
));
117117

118-
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
118+
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
119119
}
120120

121121
public function testSetDataToUninitializedEntityWithNonRequiredToString()
@@ -131,7 +131,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredToString()
131131
'required' => false,
132132
));
133133

134-
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
134+
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
135135
}
136136

137137
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@@ -150,7 +150,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
150150
'query_builder' => $qb
151151
));
152152

153-
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
153+
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
154154
}
155155

156156
/**
@@ -494,7 +494,7 @@ public function testOverrideChoices()
494494

495495
$field->bind('2');
496496

497-
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
497+
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
498498
$this->assertTrue($field->isSynchronized());
499499
$this->assertSame($entity2, $field->getData());
500500
$this->assertSame('2', $field->getClientData());
@@ -524,7 +524,7 @@ public function testGroupByChoices()
524524
'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
525525
'Group2' => array(3 => new ChoiceView('3', 'Baz')),
526526
'4' => new ChoiceView('4', 'Boo!')
527-
), $field->createView()->get('choices'));
527+
), $field->createView()->getVar('choices'));
528528
}
529529

530530
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function isChoiceGroup($label)
9898

9999
public function isChoiceSelected(FormView $view, ChoiceView $choice)
100100
{
101-
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
101+
return FormUtil::isChoiceSelected($choice->getValue(), $view->getVar('value'));
102102
}
103103

104104
/**
@@ -228,7 +228,7 @@ protected function render(FormView $view, $section, array $variables = array())
228228
}
229229
}
230230

231-
$custom = '_'.$view->get('id');
231+
$custom = '_'.$view->getVar('id');
232232
$rendering = $custom.$section;
233233
$blocks = $this->getBlocks($view);
234234

@@ -237,11 +237,11 @@ protected function render(FormView $view, $section, array $variables = array())
237237
$types = $this->varStack[$rendering]['types'];
238238
$this->varStack[$rendering]['variables'] = array_replace_recursive($this->varStack[$rendering]['variables'], $variables);
239239
} else {
240-
$types = $view->get('types');
240+
$types = $view->getVar('types');
241241
$types[] = $custom;
242242
$typeIndex = count($types) - 1;
243243
$this->varStack[$rendering] = array(
244-
'variables' => array_replace_recursive($view->all(), $variables),
244+
'variables' => array_replace_recursive($view->getVars(), $variables),
245245
'types' => $types,
246246
);
247247
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php if ($form->get('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
1+
<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function isChoiceGroup($label)
6666

6767
public function isChoiceSelected(FormView $view, ChoiceView $choice)
6868
{
69-
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
69+
return FormUtil::isChoiceSelected($choice->getValue(), $view->getVar('value'));
7070
}
7171

7272
/**
@@ -79,7 +79,7 @@ public function isChoiceSelected(FormView $view, ChoiceView $choice)
7979
*/
8080
public function setTheme(FormView $view, $themes)
8181
{
82-
$this->themes[$view->get('id')] = (array) $themes;
82+
$this->themes[$view->getVar('id')] = (array) $themes;
8383
$this->templates = array();
8484
}
8585

@@ -237,18 +237,18 @@ protected function renderSection(FormView $view, $section, array $variables = ar
237237

238238
$template = null;
239239

240-
$custom = '_'.$view->get('id');
240+
$custom = '_'.$view->getVar('id');
241241
$rendering = $custom.$section;
242242

243243
if (isset($this->varStack[$rendering])) {
244244
$typeIndex = $this->varStack[$rendering]['typeIndex'] - 1;
245245
$types = $this->varStack[$rendering]['types'];
246246
$variables = array_replace_recursive($this->varStack[$rendering]['variables'], $variables);
247247
} else {
248-
$types = $view->get('types');
248+
$types = $view->getVar('types');
249249
$types[] = $custom;
250250
$typeIndex = count($types) - 1;
251-
$variables = array_replace_recursive($view->all(), $variables);
251+
$variables = array_replace_recursive($view->getVars(), $variables);
252252
$this->varStack[$rendering]['types'] = $types;
253253
}
254254

@@ -330,7 +330,7 @@ public function getName()
330330
protected function lookupTemplate(FormView $view, $block)
331331
{
332332
$file = $block.'.html.php';
333-
$id = $view->get('id');
333+
$id = $view->getVar('id');
334334

335335
if (!isset($this->templates[$id][$block])) {
336336
$template = false;

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ CHANGELOG
133133
FormEvents::BIND_NORM_DATA
134134
* [BC BREAK] reversed the order of the first two arguments to `createNamed`
135135
and `createNamedBuilder` in `FormFactoryInterface`
136+
* [BC BREAK] adapted methods of FormView to match the naming used in
137+
FormInterface and FormBuilder
138+
* deprecated `getChildren` in Form and FormBuilder in favor of `all`
139+
* deprecated `hasChildren` in Form and FormBuilder in favor of `count`
140+
* FormBuilder now implements \IteratorAggregate

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function buildForm(FormBuilderInterface $builde F438 r, array $options)
3535
*/
3636
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
3737
{
38-
$view
39-
->set('value', $options['value'])
40-
->set('checked', null !== $form->getViewData())
41-
;
38+
$view->setVars(array(
39+
'value' => $options['value'],
40+
'checked' => null !== $form->getViewData(),
41+
));
4242
}
4343

4444
/**

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7575
*/
7676
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
7777
{
78-
$view
79-
->set('multiple', $options['multiple'])
80-
->set('expanded', $options['expanded'])
81-
->set('preferred_choices', $options['choice_list']->getPreferredViews())
82-
->set('choices', $options['choice_list']->getRemainingViews())
83-
->set('separator', '-------------------')
84-
->set('empty_value', $options['empty_value'])
85-
;
78+
$view->setVars(array(
79+
'multiple' => $options['multiple'],
80+
'expanded' => $options['expanded'],
81+
'preferred_choices' => $options['choice_list']->getPreferredViews(),
82+
'choices' => $options['choice_list']->getRemainingViews(),
83+
'separator' => '-------------------',
84+
'empty_value' => $options['empty_value'],
85+
));
8686

8787
if ($options['multiple'] && !$options['expanded']) {
8888
// Add "[]" to the name in case a select tag with multiple options is
8989
// displayed. Otherwise only one of the selected options is sent in the
9090
// POST request.
91-
$view->set('full_name', $view->get('full_name').'[]');
91+
$view->setVar('full_name', $view->getVar('full_name').'[]');
9292
}
9393
}
9494

@@ -99,15 +99,15 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
9999
{
100100
if ($options['expanded']) {
101101
// Radio buttons should have the same name as the parent
102-
$childName = $view->get('full_name');
102+
$childName = $view->getVar('full_name');
103103

104104
// Checkboxes should append "[]" to allow multiple selection
105105
if ($options['multiple']) {
106106
$childName .= '[]';
107107
}
108108

109-
foreach ($view->getChildren() as $childView) {
110-
$childView->set('full_name', $childName);
109+
foreach ($view as $childView) {
110+
$childView->setVar('full_name', $childName);
111111
}
112112
}
113113
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4848
*/
4949
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
5050
{
51-
$view
52-
->set('allow_add', $options['allow_add'])
53-
->set('allow_delete', $options['allow_delete'])
54-
;
51+
$view->setVars(array(
52+
'allow_add' => $options['allow_add'],
53+
'allow_delete' => $options['allow_delete'],
54+
));
5555

5656
if ($form->getConfig()->hasAttribute('prototype')) {
57-
$view->set('prototype', $form->getConfig()->getAttribute('prototype')->createView($view));
57+
$view->setVar('prototype', $form->getConfig()->getAttribute('prototype')->createView($view));
5858
}
5959
}
6060

@@ -63,8 +63,8 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o
6363
*/
6464
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
6565
{
66-
if ($form->getConfig()->hasAttribute('prototype') && $view->get('prototype')->get('multipart')) {
67-
$view->set('multipart', true);
66+
if ($form->getConfig()->hasAttribute('prototype') && $view->getVar('prototype')->getVar('multipart')) {
67+
$view->setVar('multipart', true);
6868
}
6969
}
7070

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
118118
*/
119119
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
120120
{
121-
$view->set('widget', $options['widget']);
121+
$view->setVar('widget', $options['widget']);
122122

123123
if ('single_text' === $options['widget']) {
124-
$view->set('type', 'datetime');
124+
$view->setVar('type', 'datetime');
125125
}
126126
}
127127

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
138138
*/
139139
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
140140
{
141-
$view->set('widget', $options['widget']);
141+
$view->setVar('widget', $options['widget']);
142142

143143
if ('single_text' === $options['widget']) {
144-
$view->set('type', 'date');
144+
$view->setVar('type', 'date');
145145
}
146146

147147
if ($view->hasChildren()) {
@@ -156,7 +156,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
156156
$pattern = '{{ year }}-{{ month }}-{{ day }}';
157157
}
158158

159-
$view->set('date_pattern', $pattern);
159+
$view->setVar('date_pattern', $pattern);
160160
}
161161
}
162162

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class FileType extends AbstractType
2323
*/
2424
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
2525
{
26-
$view
27-
->set('type', 'file')
28-
->set('value', '')
29-
;
26+
$view->setVars(array(
27+
'type' => 'file',
28+
'value' => '',
29+
));
3030
}
3131

3232
/**
@@ -35,7 +35,7 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o
3535
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
3636
{
3737
$view
38-
->set('multipart', true)
38+
->setVar('multipart', true)
3939
;
4040
}
4141

0 commit comments

Comments
 (0)
0