8000 Rename CollectionType options for entries · symfony/symfony@d59f2a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d59f2a5

Browse files
committed
Rename CollectionType options for entries
1 parent c498389 commit d59f2a5

File tree

5 files changed

+63
-37
lines changed

5 files changed

+63
-37
lines changed

src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ class ResizeFormListener implements EventSubscriberInterface
2525
{
2626
/**
2727
* @var string
28+
*
29+
* @deprecated since version 2.7, will be replaced by a $entryType private property in 3.0.
2830
*/
2931
protected $type;
3032

3133
/**
3234
* @var array
35+
*
36+
* @deprecated since version 2.7, will be replaced by a $entryOptions private property in 3.0.
3337
*/
3438
protected $options;
3539

@@ -52,12 +56,12 @@ class ResizeFormListener implements EventSubscriberInterface
5256
*/
5357
private $deleteEmpty;
5458

55-
public function __construct($type, array $options = array(), $allowAdd = false, $allowDelete = false, $deleteEmpty = false)
59+
public function __construct($entryType, array $entryOptions = array(), $allowAdd = false, $allowDelete = false, $deleteEmpty = false)
5660
{
57-
$this->type = $type;
61+
$this->type = $entryType;
5862
$this->allowAdd = $allowAdd;
5963
$this->allowDelete = $allowDelete;
60-
$this->options = $options;
64+
$this->options = $entryOptions;
6165
$this->deleteEmpty = $deleteEmpty;
6266
}
6367

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class CollectionType extends AbstractType
2727
public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
2929
if ($options['allow_add'] && $options['prototype']) {
30-
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
30+
$prototype = $builder->create($options['prototype_name'], $options['entry_type'], array_replace(array(
3131
'label' => $options['prototype_name'].'label__',
32-
), $options['options']));
32+
), $options['entry_options']));
3333
$builder->setAttribute('prototype', $prototype->getForm());
3434
}
3535

3636
$resizeListener = new ResizeFormListener(
37-
$options['type'],
38-
$options['options'],
37+
$options['entry_type'],
38+
$options['entry_options'],
3939
$options['allow_add'],
4040
$options['allow_delete'],
4141
$options['delete_empty']
@@ -74,23 +74,45 @@ public function finishView(FormView $view, FormInterface $form, array $options)
7474
*/
7575
public function configureOptions(OptionsResolver $resolver)
7676
{
77-
$optionsNormalizer = function (Options $options, $value) {
77+
$entryOptionsNormalizer = function (Options $options, $value) {
7878
$value['block_name'] = 'entry';
7979

8080
return $value;
8181
};
82+
$entryType = function (Options $options) {
83+
if (null !== $options['type']) {
84+
trigger_error('The form option "type" is deprecated since version 2.7 and will be removed in 3.0. Use "entry_type" instead.', E_USER_DEPRECATED);
85+
86+
return $options['type'];
87+
}
88+
89+
return 'text';
90+
};
91+
$entryOptions = function (Options $options) {
92+
if (null !== $options['options']) {
93+
trigger_error('The form option "options" is deprecated since version 2.7 and will be removed in 3.0. Use "entry_options" instead.', E_USER_DEPRECATED);
94+
95+
return $options['options'];
96+
}
97+
98+
return array();
99+
};
82100

83101
$resolver->setDefaults(array(
84102
'allow_add' => false,
85103
'allow_delete' => false,
86104
'prototype' => true,
87105
'prototype_name' => '__name__',
88-
'type' => 'text',
89-
'options' => array(),
106+
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0. Use entry_type instead
107+
'type' => null,
108+
// deprecated as of Symfony 2.7, to be removed in Symfony 3.0. Use entry_options instead
109+
'options' => null,
110+
'entry_type' => $entryType,
111+
'entry_options' => $entryOptions,
90112
'delete_empty' => false,
91113
));
92114

93-
$resolver->setNormalizer('options', $optionsNormalizer);
115+
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);
94116
}
95117

96118
/**

src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function testRestAndRepeatedWithWidgetPerChild()
285285
public function testCollection()
286286
{
287287
$form = $this->factory->createNamed('names', 'collection', array('a', 'b'), array(
288-
'type' => 'text',
288+
'entry_type' => 'text',
289289
));
290290

291291
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -307,7 +307,7 @@ public function testCollectionWithAlternatingRowTypes()
307307
array('title' => 'b'),
308308
);
309309
$form = $this->factory->createNamed('names', 'collection', $data, array(
310-
'type' => new AlternatingRowType(),
310+
'entry_type' => new AlternatingRowType(),
311311
));
312312

313313
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -325,7 +325,7 @@ public function testCollectionWithAlternatingRowTypes()
325325
public function testEmptyCollection()
326326
{
327327
$form = $this->factory->createNamed('names', 'collection', array(), array(
328-
'type' => 'text',
328+
'entry_type' => 'text',
329329
));
330330

331331
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -342,7 +342,7 @@ public function testCollectionRow()
342342
'collection',
343343
'collection',
344344
array('a', 'b'),
345-
array('type' => 'text')
345+
array('entry_type' => 'text')
346346
);
347347

348348
$form = $this->factory->createNamedBuilder('form', 'form')

src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
2020
public function testContainsNoChildByDefault()
2121
{
2222
$form = $this->factory->create('collection', null, array(
23-
'type' => 'text',
23+
'entry_type' => 'text',
2424
));
2525

2626
$this->assertCount(0, $form);
@@ -29,8 +29,8 @@ public function testContainsNoChildByDefault()
2929
public function testSetDataAdjustsSize()
3030
{
3131
$form = $this->factory->create('collection', null, array(
32-
'type' => 'text',
33-
'options' => array(
32+
'entry_type' => 'text',
33+
'entry_options' => array(
3434
'attr' => array('maxlength' => 20),
3535
),
3636
));
@@ -58,7 +58,7 @@ public function testSetDataAdjustsSize()
5858
public function testThrowsExceptionIfObjectIsNotTraversable()
5959
{
6060
$form = $this->factory->create('collection', null, array(
61-
'type' => 'text',
61+
'entry_type' => 'text',
6262
));
6363
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
6464
$form->setData(new \stdClass());
@@ -67,7 +67,7 @@ public function testThrowsExceptionIfObjectIsNotTraversable()
6767
public function testNotResizedIfSubmittedWithMissingData()
6868
{
6969
$form = $this->factory->create('collection', null, array(
70-
'type' => 'text',
70+
'entry_type' => 'text',
7171
));
7272
$form->setData(array('foo@foo.com', 'bar@bar.com'));
7373
$form->submit(array('foo@bar.com'));
@@ -81,7 +81,7 @@ public function testNotResizedIfSubmittedWithMissingData()
8181
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
8282
{
8383
$form = $this->factory->create('collection', null, array(
84-
'type' => 'text',
84+
'entry_type' => 'text',
8585
'allow_delete' => true,
8686
));
8787
$form->setData(array('foo@foo.com', 'bar@bar.com'));
@@ -96,7 +96,7 @@ public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
9696
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
9797
{
9898
$form = $this->factory->create('collection', null, array(
99-
'type' => 'text',
99+
'entry_type' => 'text',
100100
'allow_delete' => true,
101101
'delete_empty' => true,
102102
));
@@ -113,7 +113,7 @@ public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
113113
public function testDontAddEmptyDataIfDeleteEmpty()
114114
{
115115
$form = $this->factory->create('collection', null, array(
116-
'type' => 'text',
116+
'entry_type' => 'text',
117117
'allow_add' => true,
118118
'delete_empty' => true,
119119
));
@@ -130,7 +130,7 @@ public function testDontAddEmptyDataIfDeleteEmpty()
130130
public function testNoDeleteEmptyIfDeleteNotAllowed()
131131
{
132132
$form = $this->factory->create('collection', null, array(
133-
'type' => 'text',
133+
'entry_type' => 'text',
134134
'allow_delete' => false,
135135
'delete_empty' => true,
136136
));
@@ -145,10 +145,10 @@ public function testNoDeleteEmptyIfDeleteNotAllowed()
145145
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
146146
{
147147
$form = $this->factory->create('collection', null, array(
148-
'type' => new AuthorType(),
148+
'entry_type' => new AuthorType(),
149149
// If the field is not required, no new Author will be created if the
150150
// form is completely empty
151-
'options' => array('required' => false),
151+
'entry_options' => array('required' => false),
152152
'allow_add' => true,
153153
'delete_empty' => true,
154154
));
@@ -168,7 +168,7 @@ public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
168168
public function testNotResizedIfSubmittedWithExtraData()
169169
{
170170
$form = $this->factory->create('collection', null, array(
171-
'type' => 'text',
171+
'entry_type' => 'text',
172172
));
173173
$form->setData(array('foo@bar.com'));
174174
$form->submit(array('foo@foo.com', 'bar@bar.com'));
@@ -181,7 +181,7 @@ public function testNotResizedIfSubmittedWithExtraData()
181181
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
182182
{
183183
$form = $this->factory->create('collection', null, array(
184-
'type' => 'text',
184+
'entry_type' => 'text',
185185
'allow_add' => true,
186186
));
187187
$form->setData(array('foo@bar.com'));
@@ -197,7 +197,7 @@ public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
197197
public function testAllowAddButNoPrototype()
198198
{
199199
$form = $this->factory->create('collection', null, array(
200-
'type' => 'form',
200+
'entry_type' => 'form',
201201
'allow_add' => true,
202202
'prototype' => false,
203203
));
@@ -209,7 +209,7 @@ public function testPrototypeMultipartPropagation()
209209
{
210210
$form = $this->factory
211211
->create('collection', null, array(
212-
'type' => 'file',
212+
'entry_type' => 'file',
213213
'allow_add' => true,
214214
'prototype' => true,
215215
))
@@ -221,7 +221,7 @@ public function testPrototypeMultipartPropagation()
221221
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
222222
{
223223
$form = $this->factory->create('collection', array(), array(
224-
'type' => 'file',
224+
'entry_type' => 'file',
225225
'prototype' => true,
226226
'allow_add' => true,
227227
));
@@ -233,7 +233,7 @@ public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
233233
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
234234
{
235235
$form = $this->factory->create('collection', array(), array(
236-
'type' => 'file',
236+
'entry_type' => 'file',
237237
'allow_add' => true,
238238
'prototype' => true,
239239
));
@@ -246,15 +246,15 @@ public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
246246
public function testPrototypeNameOption()
247247
{
248248
$form = $this->factory->create('collection', null, array(
249-
'type' => 'form',
249+
'entry_type' => 'form',
250250
'prototype' => true,
251251
'allow_add' => true,
252252
));
253253

254254
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
255255

256256
$form = $this->factory->create('collection', null, array(
257-
'type' => 'form',
257+
'entry_type' => 'form',
258258
'prototype' => true,
259259
'allow_add' => true,
260260
'prototype_name' => '__test__',
@@ -266,7 +266,7 @@ public function testPrototypeNameOption()
266266
public function testPrototypeDefaultLabel()
267267
{
268268
$form = $this->factory->create('collection', array(), array(
269-
'type' => 'file',
269+
'entry_type' => 'file',
270270
'allow_add' => true,
271271
'prototype' => true,
272272
'prototype_name' => '__test__',

src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ public function testNoCsrfProtectionOnPrototype()
352352
{
353353
$prototypeView = $this->factory
354354
->create('collection', null, array(
355-
'type' => new FormTypeCsrfExtensionTest_ChildType(),
356-
'options' => array(
355+
'entry_type' => new FormTypeCsrfExtensionTest_ChildType(),
356+
'entry_options' => array(
357357
'csrf_field_name' => 'csrf',
358358
),
359359
'prototype' => true,

0 commit comments

Comments
 (0)
0