-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
Your proposal is not BC |
@stof What breaks BC? |
public function testGetOptionsResolverWithConfigureOptions() | ||
{ | ||
if (version_compare(\PHPUnit_Runner_Version::id(), '3.7', '<')) { | ||
$this->markTestSkipped('This test requires PHPUnit 3.7.'); |
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.
This is useless. The Symfony testsuite already requires 4.2+ anyway
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.
It is useless, but there are several of those conditions in this test class.
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.
I have just copied it from the test class with the old configuration name.
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.
Well, checking for <3.7 was useful 4 years ago, when 3.7 was just released and many people were still running 3.6. Now, it is not
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.
Shall I remove it in the entire class? Can you provide some more information regarding BC breaks you mentioned?
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.
We removed all those skips recently, please remove this one also.
@webmozart What is your opinion regarding this? |
Any opinion on this PR? |
* | ||
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
setDefaultOptions
must call configureOptions
to be BC
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.
It is BC compatible hence the checks for configureOptions in ResolvedFormType
. See also my comments there.
@fabpot I think this is a valuable change:
|
Indeed, this looks like a very good change. @peterrehm Besides the comments from @stof, you must add the deprecation notices where applicable before we can merge this PR. There are some other things to take care of like moving tests for the old version into "legacy" tests, but I will let @nicolas-grekas comment on this. |
As @fabpot said, please trigger deprecations notices when the deprecated methods are used (see #13060). |
to be clear, the case needing to throw a notice is when a type is overwriting setDefaultOptions instead of overwriting configureOptions. The code using the types should still call the |
I have just added a way to check if the method has been overwritten in the |
@@ -205,8 +205,30 @@ public function getOptionsResolver() | |||
|
|||
$this->innerType->setDefaultOptions($this->optionsResolver); | |||
|
|||
$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions'); | |||
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'AbstractType'); |
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.
This will never work, because the class name is not AbstractType. So it will always be reported as overwritten
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.
Refactored with the FQN.
Most likely due to my local squash the comment by @stof got lost:
|
I have done a rewrite as per @stof's comment in a second commit. It could potentially break if someone has a custom OptionResolver implementation which is i assume unlikely. What do you think now? |
This is totally unlikely (which is why the interface is deprecated btw) and even more in the case of forms given that the OptionsResolver is instantiated by Symfony |
} | ||
|
||
/** | ||
* Configure the options for this type. |
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.
typo: Configures
Yes I just wanted to have it mentioned. |
* The method `AbstractType::setDefaultOptions(OptionsResolverInterface $resolver)` and | ||
`AbstractTypeExtension::setDefaultOptions(OptionsResolverInterface $resolver)` have been | ||
removed. 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 comment
The 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 comment
The 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 comment
The 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
for the components=high, this is because the subtree split of the Form component obviously does not contain the change for configureOptions yet. It should be fixed once the PR is merged and subtrees get updated. For components=low, this is a combination of 2 things:
|
Thanks for the explanation, that makes it clear. Then I am good from my side. |
no you're not. You need to bump the lower bound for the Form component in other components/bridges where you switched to configureOptions |
I have adjusted the version requirements, Is this as you expected it? |
Rebased. Now it looks like just the Tests in the Doctrine and Propel bridge are failing, I assume this is due to the missing subtree split. |
@@ -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 |
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.
@fabpot Is there anything blocking this? |
2.7.0 | ||
----- | ||
|
||
* deprecated AbstractType::setDefaultOptions() in favor of AbstractType::configureOptions(). |
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.
actually, what has been deprecated is overriding these methods
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.
setDefaultOptions() has ben deprecated and the new method exists as preparation for the rename in 3.0.
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.
no. the method itself is not deprecated (it is not possible as it must be implemented in form types and is being used.
What is deprecated is overwriting AbstractType::setDefaultOptions()
, in favor of overwriting AbstractType::configureOptions()
, to use a forward-compatibility layer.
This is not a BC layer here. We are making it possible to write your code as if you were using the Symfony 3 interface already, even though it is not the case yet, handling the differences in the parent class. This is not the same than providing a new API and deprecating the BC layer
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.
Well I still consider this as deprecated. Do you want me to change the wording?
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.
I would vote for updating the wording
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.
@stof updated as per your request.
The UPGRADE-2.7 file should mention the deprecation and describe the way to upgrade |
@stof Added the upgrade information |
@stof Anything else left? |
@@ -22,7 +22,7 @@ | |||
}, | |||
"require-dev": { | |||
"symfony/finder": "~2.3|~3.0.0", | |||
"symfony/form": "~2.6|~3.0.0", | |||
"symfony/form": "~2.7|~3.0.0", |
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.
this is not needed actually AFAIK. The Twig bridge does not contain a form type
@stof Updated as per your comments. |
@peterrehm Tests do not pass (some problems on Propel seems related to this PR). Also, if not done already, rebase on current master. Thanks. |
@fabpot So is it okay now? |
Thank you @peterrehm. |
…igureOptions() (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()
Perfect. Once you merge 2.7 into master I will update #13407. |
…method (peterrehm) This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #4786). Discussion ---------- Replaced setDefaultOptions by the new configureOptions method | Q | A | ------------- | --- | Doc fix? | yes | New docs? | yes|no (PR symfony/symfony#12891) | Applies to | 2.7 | Fixed tickets | #4565 Pending on the merge of symfony/symfony#12891. With this PR all references to setDefaultOptions and the deprecated OptionResolverInterface are removed in 2.7. Commits ------- 728205f Replaced setDefaultOptions by the new configureOptions method
…ResolverInterface (peterrehm) This PR was merged into the 3.0-dev branch. Discussion ---------- [Form] Remove deprecated setDefaultOptions and OptionsResolverInterface | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#4786 | Related | #12891 Commits ------- 9b9158b Remove the deprecated OptionsResolverInterface 6026781 Removed deprecated setDefaultOptions methods
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.