From 9b76e71af53a96df70bfa07d7c411b5b83ba72fc Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 26 Sep 2015 19:00:28 +0200 Subject: [PATCH 1/3] Deprecated alias setting of form tags --- UPGRADE-2.8.md | 17 ++++++ .../Bundle/FrameworkBundle/CHANGELOG.md | 3 + .../DependencyInjection/Compiler/FormPass.php | 14 +++-- .../FrameworkBundle/Resources/config/form.xml | 8 +-- .../Resources/config/form_csrf.xml | 2 +- .../Resources/config/form_debug.xml | 2 +- .../Compiler/FormPassTest.php | 57 +++++++++++++++---- 7 files changed, 81 insertions(+), 22 deletions(-) diff --git a/UPGRADE-2.8.md b/UPGRADE-2.8.md index 5e4c0f60216ba..26b9def16751a 100644 --- a/UPGRADE-2.8.md +++ b/UPGRADE-2.8.md @@ -235,6 +235,23 @@ Form match the type returned by `getExtendedType` is now forbidden. Fix your implementation to define the right type. + * The alias option of the `form.type_extension` tag is deprecated in favor of + the `extended_type` option. + + Before: + ```xml + + + + ``` + + After: + ```xml + + + + ``` + Translator ---------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 474637d6eaf09..e7c351813ebc8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -4,6 +4,9 @@ CHANGELOG 2.8.0 ----- + * Deprecated the `alias` option of the `form.type_extension` tag in favor of the + `extended_type`/`extended-type` option + * Deprecated the `alias` option of the `form.type` tag * Deprecated the Shell 2.7.0 diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php index cc0c218e4941b..77ce79202ca95 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php @@ -53,11 +53,17 @@ public function process(ContainerBuilder $container) $typeExtensions = array(); foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) { - $alias = isset($tag[0]['alias']) - ? $tag[0]['alias'] - : $serviceId; + $extendedType = $serviceId; + if (isset($tag[0]['extended_type'])) { + $extendedType = $tag[0]['extended_type']; + } elseif (isset($tag[0]['alias'])) { + @trigger_error('The alias option of the form.type_extension tag is deprecated since version 2.8 and will be removed in 3.0. Use the extended_type option instead.', E_USER_DEPRECATED); + $extendedType = $tag[0]['alias']; + } else { + @trigger_error('The extended_type option of the form.type_extension tag is required since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } - $typeExtensions[$alias][] = $serviceId; + $typeExtensions[$extendedType][] = $serviceId; } $definition->replaceArgument(2, $typeExtensions); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml index 57611435ebc4d..7789d404bab7b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml @@ -155,7 +155,7 @@ - + @@ -169,14 +169,14 @@ - + - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml index af3289a190050..c3e2558ae4237 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml @@ -11,7 +11,7 @@ - + %form.type_extension.csrf.enabled% %form.type_extension.csrf.field_name% diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml index ddf0a4e32cfe5..ed0cfb09879e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml @@ -21,7 +21,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php index d7dc9d8a347da..05158a9ed688f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php @@ -68,6 +68,9 @@ public function testAddTaggedTypes() ), $extDefinition->getArgument(1)); } + /** + * @group legacy + */ public function testUseCustomAliasIfSet() { $container = new ContainerBuilder(); @@ -107,25 +110,20 @@ public function testAddTaggedTypeExtensions() $container = new ContainerBuilder(); $container->addCompilerPass(new FormPass()); - $extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension'); - $extDefinition->setArguments(array( + $extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array( new Reference('service_container'), array(), array(), array(), )); - $definition1 = new Definition('stdClass'); - $definition1->addTag('form.type_extension', array('alias' => 'type1')); - $definition2 = new Definition('stdClass'); - $definition2->addTag('form.type_extension', array('alias' => 'type1')); - $definition3 = new Definition('stdClass'); - $definition3->addTag('form.type_extension', array('alias' => 'type2')); - $container->setDefinition('form.extension', $extDefinition); - $container->setDefinition('my.type_extension1', $definition1); - $container->setDefinition('my.type_extension2', $definition2); - $container->setDefinition('my.type_extension3', $definition3); + $container->register('my.type_extension1', 'stdClass') + ->addTag('form.type_extension', array('extended_type' => 'type1')); + $container->register('my.type_extension2', 'stdClass') + ->addTag('form.type_extension', array('extended_type' => 'type1')); + $container->register('my.type_extension3', 'stdClass') + ->addTag('form.type_extension', array('extended_type' => 'type2')); $container->compile(); @@ -142,6 +140,41 @@ public function testAddTaggedTypeExtensions() ), $extDefinition->getArgument(2)); } + /** + * @group legacy + */ + public function testAliasOptionForTaggedTypeExtensions() + { + $container = new ContainerBuilder(); + $container->addCompilerPass(new FormPass()); + + $extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array( + new Reference('service_container'), + array(), + array(), + array(), + )); + + $container->setDefinition('form.extension', $extDefinition); + $container->register('my.type_extension1', 'stdClass') + ->addTag('form.type_extension', array('alias' => 'type1')); + $container->register('my.type_extension2', 'stdClass') + ->addTag('form.type_extension', array('alias' => 'type2')); + + $container->compile(); + + $extDefinition = $container->getDefinition('form.extension'); + + $this->assertSame(array( + 'type1' => array( + 'my.type_extension1', + ), + 'type2' => array( + 'my.type_extension2', + ), + ), $extDefinition->getArgument(2)); + } + public function testAddTaggedGuessers() { $container = new ContainerBuilder(); From 28dcc723837ac07a61be18f4e2f1fd6edf95f1e2 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Thu, 1 Oct 2015 16:26:58 +0200 Subject: [PATCH 2/3] Explicitely mention extended-type as well --- UPGRADE-2.8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE-2.8.md b/UPGRADE-2.8.md index 26b9def16751a..ae8bb7fa4ac98 100644 --- a/UPGRADE-2.8.md +++ b/UPGRADE-2.8.md @@ -236,7 +236,7 @@ Form implementation to define the right type. * The alias option of the `form.type_extension` tag is deprecated in favor of - the `extended_type` option. + the `extended_type`/`extended-type` option. Before: ```xml From e539666584db012689dbd13aa48036f1958a2713 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Thu, 1 Oct 2015 16:27:53 +0200 Subject: [PATCH 3/3] Minimalize changes when removing deprecated features --- .../FrameworkBundle/DependencyInjection/Compiler/FormPass.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php index 77ce79202ca95..7b4533928c9ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php @@ -53,7 +53,7 @@ public function process(ContainerBuilder $container) $typeExtensions = array(); foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) { - $extendedType = $serviceId; + $extendedType = null; if (isset($tag[0]['extended_type'])) { $extendedType = $tag[0]['extended_type']; } elseif (isset($tag[0]['alias'])) { @@ -61,6 +61,7 @@ public function process(ContainerBuilder $container) $extendedType = $tag[0]['alias']; } else { @trigger_error('The extended_type option of the form.type_extension tag is required since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + $extendedType = $serviceId; } $typeExtensions[$extendedType][] = $serviceId;