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 d3b8b84

Browse filesBrowse files
committed
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
2 parents 6f3c6b4 + 811b711 commit d3b8b84
Copy full SHA for d3b8b84

File tree

Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ResolvedFormType.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,25 @@ public function getOptionsResolver()
206206
$this->innerType->setDefaultOptions($this->optionsResolver);
207207

208208
$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
209-
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType');
209+
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
210210

211-
if (true === $isOverwritten) {
211+
$reflector = new \ReflectionMethod($this->innerType, 'configureOptions');
212+
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
213+
214+
if ($isOldOverwritten && !$isNewOverwritten) {
212215
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);
213216
}
214217

215218
foreach ($this->typeExtensions as $extension) {
216219
$extension->setDefaultOptions($this->optionsResolver);
217220

218221
$reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
219-
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension');
222+
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
223+
224+
$reflector = new \ReflectionMethod($extension, 'configureOptions');
225+
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
220226

221-
if (true === $isOverwritten) {
227+
if ($isOldOverwritten && !$isNewOverwritten) {
222228
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);
223229
}
224230
}

0 commit comments

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