Skip to content

Commit 63c4964

Browse files
committed
bug #15101 [Form] Fixed compatibility with FormTypeInterface implementations that don't extend AbstractType (webmozart)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fixed compatibility with FormTypeInterface implementations that don't extend AbstractType | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 4a1ad7e [Form] Fixed compatibility with FormTypeInterface implementations that don't extend AbstractType
2 parents 550b25b + 42d317f commit 63c4964

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

ResolvedFormType.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,27 +200,35 @@ public function getOptionsResolver()
200200

201201
$this->innerType->setDefaultOptions($this->optionsResolver);
202202

203-
$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
204-
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
203+
if (method_exists($this->innerType, 'configureOptions')) {
204+
$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
205+
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
205206

206-
$reflector = new \ReflectionMethod($this->innerType, 'configureOptions');
207-
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
207+
$reflector = new \ReflectionMethod($this->innerType, 'configureOptions');
208+
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType';
208209

209-
if ($isOldOverwritten && !$isNewOverwritten) {
210-
@trigger_error(get_class($this->innerType).': 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);
210+
if ($isOldOverwritten && !$isNewOverwritten) {
211+
@trigger_error(get_class($this->innerType).': 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);
212+
}
213+
} else {
214+
@trigger_error(get_class($this->innerType).': The FormTypeInterface::configureOptions() method will be added in Symfony 3.0. You should extend AbstractType or implement it in your classes.', E_USER_DEPRECATED);
211215
}
212216

213217
foreach ($this->typeExtensions as $extension) {
214218
$extension->setDefaultOptions($this->optionsResolver);
215219

216-
$reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
217-
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
220+
if (method_exists($extension, 'configureOptions')) {
221+
$reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
222+
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
218223

219-
$reflector = new \ReflectionMethod($extension, 'configureOptions');
220-
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
224+
$reflector = new \ReflectionMethod($extension, 'configureOptions');
225+
$isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension';
221226

222-
if ($isOldOverwritten && !$isNewOverwritten) {
223-
@trigger_error(get_class($extension).': 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);
227+
if ($isOldOverwritten && !$isNewOverwritten) {
228+
@trigger_error(get_class($extension).': 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);
229+
}
230+
} else {
231+
@trigger_error(get_class($this->innerType).': The FormTypeExtensionInterface::configureOptions() method will be added in Symfony 3.0. You should extend AbstractTypeExtension or implement it in your classes.', E_USER_DEPRECATED);
224232
}
225233
}
226234
}

0 commit comments

Comments
 (0)