Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fef2bd4

Browse filesBrowse files
committed
feature #12891 [Form] Deprecated setDefaultOptions() in favor of configureOptions() (peterrehm)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] Deprecated setDefaultOptions() in favor of configureOptions() | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | | Fixed tickets | #12782 | License | MIT | Doc PR | symfony/symfony-docs#4786 This tries to provide a compatible API with the depreciation of the OptionResolverInterface. I would like to have this in 2.6.2 but I think that might not be possible? To me I think we should always provide an API where you do not need to use deprecated classes. Also can you think of any way to trigger errors on the use of the deprecated setDefaultOptions() method? Since it is usually overwritten without calling the parent class this might be tricky. Maybe only in the resolver if we can check if actual options has been resolved in a call to setDefaultOptions. Commits ------- 3d43cae Deprecated setDefaultOptions() in favor of configureOptions()
2 parents 388ae55 + 3d43cae commit fef2bd4
Copy full SHA for fef2bd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

46 files changed

+183
-85
lines changed

‎UPGRADE-2.7.md

Copy file name to clipboardExpand all lines: UPGRADE-2.7.md
+45-1Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
UPGRADE FROM 2.6 to 2.7
22
=======================
33

4-
### Router
4+
Router
5+
------
56

67
* Route conditions now support container parameters which
78
can be injected into condition using `%parameter%` notation.
@@ -15,3 +16,46 @@ UPGRADE FROM 2.6 to 2.7
1516
but in 2.7 you would get an error if `bar` parameter
1617
doesn't exist or unexpected result otherwise.
1718

19+
Form
20+
----
21+
22+
* In form types and extension overriding the "setDefaultOptions" of the
23+
AbstractType or AbstractExtensionType has been deprecated in favor of
24+
overriding the new "configureOptions" method.
25+
26+
The method "setDefaultOptions(OptionsResolverInterface $resolver)" will
27+
be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)".
28+
29+
Before:
30+
31+
```php
32+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
33+
34+
class TaskType extends AbstractType
35+
{
36+
// ...
37+
public function setDefaultOptions(OptionsResolverInterface $resolver)
38+
{
39+
$resolver->setDefaults(array(
40+
'data_class' => 'AppBundle\Entity\Task',
41+
));
42+
}
43+
}
44+
```
45+
46+
After:
47+
48+
```php
49+
use Symfony\Component\OptionsResolver\OptionsResolver;
50+
51+
class TaskType extends AbstractType
52+
{
53+
// ...
54+
public function configureOptions(OptionsResolver $resolver)
55+
{
56+
$resolver->setDefaults(array(
57+
'data_class' => 'AppBundle\Entity\Task',
58+
));
59+
}
60+
}
61+
```

‎UPGRADE-3.0.md

Copy file name to clipboardExpand all lines: UPGRADE-3.0.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ UPGRADE FROM 2.x to 3.0
106106

107107
### Form
108108

109+
* The method `AbstractType::setDefaultOptions(OptionsResolverInterface $resolver)` and
110+
`AbstractTypeExtension::setDefaultOptions(OptionsResolverInterface $resolver)` have been
111+
renamed. You should use `AbstractType::configureOptions(OptionsResolver $resolver)` and
112+
`AbstractTypeExtension::configureOptions(OptionsResolver $resolver)` instead.
113+
109114
* The methods `Form::bind()` and `Form::isBound()` were removed. You should
110115
use `Form::submit()` and `Form::isSubmitted()` instead.
111116

‎src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
2222
use Symfony\Component\Form\AbstractType;
2323
use Symfony\Component\OptionsResolver\Options;
24-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
24+
use Symfony\Component\OptionsResolver\OptionsResolver;
2525
use Symfony\Component\PropertyAccess\PropertyAccess;
2626
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
2727

@@ -58,7 +58,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5858
}
5959
}
6060

61-
public function setDefaultOptions(OptionsResolverInterface $resolver)
61+
public function configureOptions(OptionsResolver $resolver)
6262
{
6363
$choiceListCache = & $this->choiceListCache;
6464
$registry = $this->registry;

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"symfony/stopwatch": "~2.2|~3.0.0",
2424
"symfony/dependency-injection": "~2.2|~3.0.0",
25-
"symfony/form": "~2.3,>=2.3.8|~3.0.0",
25+
"symfony/form": "~2.7|~3.0.0",
2626
"symfony/http-kernel": "~2.2|~3.0.0",
2727
"symfony/property-access": "~2.3|~3.0.0",
2828
"symfony/security": "~2.2|~3.0.0",

‎src/Symfony/Bridge/Propel1/Form/Type/ModelType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/Form/Type/ModelType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Form\AbstractType;
1717
use Symfony\Component\Form\FormBuilderInterface;
1818
use Symfony\Component\OptionsResolver\Options;
19-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
19+
use Symfony\Component\OptionsResolver\OptionsResolver;
2020
use Symfony\Component\PropertyAccess\PropertyAccess;
2121
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
2222

@@ -78,7 +78,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7878
/**
7979
* {@inheritdoc}
8080
*/
81-
public function setDefaultOptions(OptionsResolverInterface $resolver)
81+
public function configureOptions(OptionsResolver $resolver)
8282
{
8383
$propertyAccessor = $this->propertyAccessor;
8484

‎src/Symfony/Bridge/Propel1/Form/Type/TranslationCollectionType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/Form/Type/TranslationCollectionType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
1616
use Symfony\Component\Form\FormBuilderInterface;
17-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
1818
use Symfony\Bridge\Propel1\Form\EventListener\TranslationCollectionFormListener;
1919

2020
/**
@@ -59,7 +59,7 @@ public function getName()
5959
/**
6060
* {@inheritdoc}
6161
*/
62-
public function setDefaultOptions(OptionsResolverInterface $resolver)
62+
public function configureOptions(OptionsResolver $resolver)
6363
{
6464
$resolver->setRequired(array(
6565
'languages',

‎src/Symfony/Bridge/Propel1/Form/Type/TranslationType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/Form/Type/TranslationType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\FormBuilderInterface;
16-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
1717
use Symfony\Bridge\Propel1\Form\EventListener\TranslationFormListener;
1818

1919
/**
@@ -44,7 +44,7 @@ public function getName()
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function setDefaultOptions(OptionsResolverInterface $resolver)
47+
public function configureOptions(OptionsResolver $resolver)
4848
{
4949
$resolver->setRequired(array(
5050
'data_class',

‎src/Symfony/Bridge/Propel1/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Propel1/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.3.9",
2020
"symfony/http-foundation": "~2.0,>=2.0.5|~3.0.0",
2121
"symfony/http-kernel": "~2.0,>=2.0.5|~3.0.0",
22-
"symfony/form": "~2.3,>=2.3.8|~3.0.0",
22+
"symfony/form": "~2.7|~3.0.0",
2323
"symfony/property-access": "~2.3|~3.0.0",
2424
"propel/propel1": "~1.6,>=1.6.5"
2525
},

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Form\FormEvents;
1818
use Symfony\Component\Form\FormEvent;
1919
use Symfony\Component\HttpFoundation\Request;
20-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
20+
use Symfony\Component\OptionsResolver\OptionsResolver;
2121
use Symfony\Component\Security\Core\Security;
2222

2323
/**
@@ -77,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function setDefaultOptions(OptionsResolverInterface $resolver)
80+
public function configureOptions(OptionsResolver $resolver)
8181
{
8282
/* Note: the form's intention must correspond to that for the form login
8383
* listener in order for the CSRF token to validate successfully.

‎src/Symfony/Component/Form/AbstractType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractType.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Component\OptionsResolver\OptionsResolver;
1415
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1516

1617
/**
@@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options)
4344
* {@inheritdoc}
4445
*/
4546
public function setDefaultOptions(OptionsResolverInterface $resolver)
47+
{
48+
$this->configureOptions($resolver);
49+
}
50+
51+
/**
52+
* Configures the options for this type.
53+
*
54+
* @param OptionsResolver $resolver The resolver for the options.
55+
*/
56+
public function configureOptions(OptionsResolver $resolver)
4657
{
4758
}
4859

‎src/Symfony/Component/Form/AbstractTypeExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/AbstractTypeExtension.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Component\OptionsResolver\OptionsResolver;
1415
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1516

1617
/**
@@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options)
4344
* {@inheritdoc}
4445
*/
4546
public function setDefaultOptions(OptionsResolverInterface $resolver)
47+
{
48+
$this->configureOptions($resolver);
49+
}
50+
51+
/**
52+
* Configures the options for this type.
53+
*
54+
* @param OptionsResolver $resolver The resolver for the options.
55+
*/
56+
public function configureOptions(OptionsResolver $resolver)
4657
{
4758
}
4859
}

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
2.7.0
5+
-----
6+
7+
* deprecated the overwriting of AbstractType::setDefaultOptions() in favor of overwriting AbstractType::configureOptions().
8+
* deprecated the overwriting of AbstractTypeExtension::setDefaultOptions() in favor of overwriting AbstractTypeExtension::configureOptions().
9+
410
2.6.2
511
-----
612

‎src/Symfony/Component/Form/Extension/Core/Type/BaseType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Form\FormBuilderInterface;
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\Form\FormView;
18-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
18+
use Symfony\Component\OptionsResolver\OptionsResolver;
1919

2020
/**
2121
* Encapsulates common logic of {@link FormType} and {@link ButtonType}.
@@ -111,7 +111,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
111111
/**
112112
* {@inheritdoc}
113113
*/
114-
public function setDefaultOptions(OptionsResolverInterface $resolver)
114+
public function configureOptions(OptionsResolver $resolver)
115115
{
116116
$resolver->setDefaults(array(
117117
'block_name' => null,

‎src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
1616

1717
class BirthdayType extends AbstractType
1818
{
1919
/**
2020
* {@inheritdoc}
2121
*/
22-
public function setDefaultOptions(OptionsResolverInterface $resolver)
22+
public function configureOptions(OptionsResolver $resolver)
2323
{
2424
$resolver->setDefaults(array(
2525
'years' => range(date('Y') - 120, date('Y')),

‎src/Symfony/Component/Form/Extension/Core/Type/ButtonType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ButtonType.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ButtonTypeInterface;
15-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
1616

1717
/**
1818
* A form button.
@@ -39,9 +39,9 @@ public function getName()
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function setDefaultOptions(OptionsResolverInterface $resolver)
42+
public function configureOptions(OptionsResolver $resolver)
4343
{
44-
parent::setDefaultOptions($resolver);
44+
parent::configureOptions($resolver);
4545

4646
$resolver->setDefaults(array(
4747
'auto_initialize' => false,

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
1818
use Symfony\Component\Form\FormView;
19-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
19+
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
class CheckboxType extends AbstractType
2222
{
@@ -49,7 +49,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4949
/**
5050
* {@inheritdoc}
5151
*/
52-
public function setDefaultOptions(OptionsResolverInterface $resolver)
52+
public function configureOptions(OptionsResolver $resolver)
5353
{
5454
$emptyData = function (FormInterface $form, $viewData) {
5555
return $viewData;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer;
2727
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToBooleanArrayTransformer;
2828
use Symfony\Component\OptionsResolver\Options;
29-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
29+
use Symfony\Component\OptionsResolver\OptionsResolver;
3030

3131
class ChoiceType extends AbstractType
3232
{
@@ -161,7 +161,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
161161
/**
162162
* {@inheritdoc}
163163
*/
164-
public function setDefaultOptions(OptionsResolverInterface $resolver)
164+
public function configureOptions(OptionsResolver $resolver)
165165
{
166166
$choiceListCache = & $this->choiceListCache;
167167

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Form\FormInterface;
1818
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
1919
use Symfony\Component\OptionsResolver\Options;
20-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
20+
use Symfony\Component\OptionsResolver\OptionsResolver;
2121

2222
class CollectionType extends AbstractType
2323
{
@@ -72,7 +72,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function setDefaultOptions(OptionsResolverInterface $resolver)
75+
public function configureOptions(OptionsResolver $resolver)
7676
{
7777
$optionsNormalizer = function (Options $options, $value) {
7878
$value['block_name'] = 'entry';

‎src/Symfony/Component/Form/Extension/Core/Type/CountryType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CountryType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Intl\Intl;
16-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
1717

1818
class CountryType extends AbstractType
1919
{
2020
/**
2121
* {@inheritdoc}
2222
*/
23-
public function setDefaultOptions(OptionsResolverInterface $resolver)
23+
public function configureOptions(OptionsResolver $resolver)
2424
{
2525
$resolver->setDefaults(array(
2626
'choices' => Intl::getRegionBundle()->getCountryNames(),

‎src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Intl\Intl;
16-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
1717

1818
class CurrencyType extends AbstractType
1919
{
2020
/**
2121
* {@inheritdoc}
2222
*/
23-
public function setDefaultOptions(OptionsResolverInterface $resolver)
23+
public function configureOptions(OptionsResolver $resolver)
2424
{
2525
$resolver->setDefaults(array(
2626
'choices' => Intl::getCurrencyBundle()->getCurrencyNames(),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.