From e3aa5226e40e49ae588040beecc1533f3efedfa9 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 26 Sep 2015 19:00:28 +0200 Subject: [PATCH] [2.8][Form] Deprecate alias tag option --- UPGRADE-2.8.md | 17 ++++++ .../Bundle/FrameworkBundle/CHANGELOG.md | 3 + .../DependencyInjection/Compiler/FormPass.php | 15 +++-- .../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, 82 insertions(+), 22 deletions(-) diff --git a/UPGRADE-2.8.md b/UPGRADE-2.8.md index 5e4c0f60216b..ae8bb7fa4ac9 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`/`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 474637d6eaf0..e7c351813ebc 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 cc0c218e4941..7b4533928c9c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php @@ -53,11 +53,18 @@ 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 = null; + 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); + $extendedType = $serviceId; + } - $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 57611435ebc4..7789d404bab7 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 af3289a19005..c3e2558ae423 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 ddf0a4e32cfe..ed0cfb09879e 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 d7dc9d8a347d..05158a9ed688 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();