minor #13811 [Form] Improve triggering of the setDefaultOptions deprecation error (WouterJ)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] Improve triggering of the setDefaultOptions deprecation error
Bundles wanting to support both Sf 2.3 and Sf 2.7 (which is a common requirement as both have at least 2 more years of maintaince) would have custom form types with both option methods defined (`setDefaultOptions` for <2.7 support and `configureOptions` for >2.7,>3.0 support). In such case, I don't think there is anything wrong with the code and a deprecation error shouldn't be triggered.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
811b711
Improve triggering of the deprecation error
This commit is contained in:
commit
d3b8b8415d
@ -206,9 +206,12 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
$this->innerType->setDefaultOptions($this->optionsResolver);
|
||||
|
||||
$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
|
||||
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType');
|
||||
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
|
||||
|
||||
if (true === $isOverwritten) {
|
||||
$reflector = new \ReflectionMethod($this->innerType, 'configureOptions');
|
||||
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
|
||||
|
||||
if ($isOldOverwritten && !$isNewOverwritten) {
|
||||
trigger_error('The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
@ -216,9 +219,12 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
$extension->setDefaultOptions($this->optionsResolver);
|
||||
|
||||
$reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
|
||||
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension');
|
||||
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
|
||||
|
||||
if (true === $isOverwritten) {
|
||||
$reflector = new \ReflectionMethod($extension, 'configureOptions');
|
||||
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
|
||||
|
||||
if ($isOldOverwritten && !$isNewOverwritten) {
|
||||
trigger_error('The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user