-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Form] Deprecated setDefaultOptions() in favor of configureOptions() #12891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
UPGRADE FROM 2.6 to 2.7 | ||
======================= | ||
|
||
Form | ||
---- | ||
|
||
* In form types and extension overriding the "setDefaultOptions" of the | ||
AbstractType or AbstractExtensionType has been deprecated in favor of | ||
overriding the new "configureOptions" method. | ||
|
||
The method "setDefaultOptions(OptionsResolverInterface $resolver)" will | ||
be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)". | ||
|
||
Before: | ||
|
||
```php | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
class TaskType extends AbstractType | ||
{ | ||
// ... | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'data_class' => 'AppBundle\Entity\Task', | ||
)); | ||
} | ||
} | ||
``` | ||
|
||
After: | ||
|
||
```php | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class TaskType extends AbstractType | ||
{ | ||
// ... | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'data_class' => 'AppBundle\Entity\Task', | ||
)); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,11 @@ UPGRADE FROM 2.x to 3.0 | |
|
||
### Form | ||
|
||
* The method `AbstractType::setDefaultOptions(OptionsResolverInterface $resolver)` and | ||
`AbstractTypeExtension::setDefaultOptions(OptionsResolverInterface $resolver)` have been | ||
renamed. You should use `AbstractType::configureOptions(OptionsResolver $resolver)` and | ||
`AbstractTypeExtension::configureOptions(OptionsResolver $resolver)` instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the actual change for 3.0 is renaming the method in the interfaces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is not only renamed, we change the signature as well. Shall i change it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, your message shows the typehint. Just keep it when showing the renaming |
||
|
||
* The methods `Form::bind()` and `Form::isBound()` were removed. You should | ||
use `Form::submit()` and `Form::isSubmitted()` instead. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\Component\Form; | ||
|
||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
/** | ||
|
@@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options) | |
* {@inheritdoc} | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$this->configureOptions($resolver); | ||
} | ||
|
||
/** | ||
* Configures the options for this type. | ||
* | ||
* @param OptionsResolver $resolver The resolver for the options. | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is BC compatible hence the checks for configureOptions in |
||
{ | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\Component\Form; | ||
|
||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
/** | ||
|
@@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options) | |
* {@inheritdoc} | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$this->configureOptions($resolver); | ||
} | ||
|
||
/** | ||
* Configures the options for this type. | ||
* | ||
* @param OptionsResolver $resolver The resolver for the options. | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the standard to use something like: "... have been deprected in favor of ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, sorry. this is the upgrade file. Maybe add a before/after example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj I think it is fine as is since before/after is already in the text.