Skip to content

Commit e7325b7

Browse files
committed
minor #15926 [2.8][Form] Deprecate alias tag option (WouterJ)
This PR was squashed before being merged into the 2.8 branch (closes #15926). Discussion ---------- [2.8][Form] Deprecate alias tag option FQCN should be used since 2.8 instead, so a deprecation error should be triggered when the `alias` setting is used. Furthermore, the name of the option doesn't make much sense for form types (as it's the alias of the field it applies to), so I renamed it to `extended_type`. I'm open to any other suggestions. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- e3aa522 [2.8][Form] Deprecate alias tag option
2 parents c434bbd + e3aa522 commit e7325b7

File tree

7 files changed

+82
-22
lines changed

7 files changed

+82
-22
lines changed

UPGRADE-2.8.md

+17
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ Form
235235
match the type returned by `getExtendedType` is now forbidden. Fix your
236236
implementation to define the right type.
237237

238+
* The alias option of the `form.type_extension` tag is deprecated in favor of
239+
the `extended_type`/`extended-type` option.
240+
241+
Before:
242+
```xml
243+
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension">
244+
<tag name="form.type_extension" alias="text" />
245+
</service>
246+
```
247+
248+
After:
249+
```xml
250+
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension">
251+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\TextType" />
252+
</service>
253+
```
254+
238255
Translator
239256
----------
240257

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CHANGELOG
44
2.8.0
55
-----
66

7+
* Deprecated the `alias` option of the `form.type_extension` tag in favor of the
8+
`extended_type`/`extended-type` option
9+
* Deprecated the `alias` option of the `form.type` tag
710
* Deprecated the Shell
811

912
2.7.0

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ public function process(ContainerBuilder $container)
5353
$typeExtensions = array();
5454

5555
foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) {
56-
$alias = isset($tag[0]['alias'])
57-
? $tag[0]['alias']
58-
: $serviceId;
56+
$extendedType = null;
57+
if (isset($tag[0]['extended_type'])) {
58+
$extendedType = $tag[0]['extended_type'];
59+
} elseif (isset($tag[0]['alias'])) {
60+
@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);
61+
$extendedType = $tag[0]['alias'];
62+
} else {
63+
@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);
64+
$extendedType = $serviceId;
65+
}
5966

60-
$typeExtensions[$alias][] = $serviceId;
67+
$typeExtensions[$extendedType][] = $serviceId;
6168
}
6269

6370
$definition->replaceArgument(2, $typeExtensions);

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<!-- FormTypeHttpFoundationExtension -->
156156
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
157157
<argument type="service" id="form.type_extension.form.request_handler" />
158-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
158+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
159159
</service>
160160

161161
<!-- HttpFoundationRequestHandler -->
@@ -169,14 +169,14 @@
169169

170170
<!-- FormTypeValidatorExtension -->
171171
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
172-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
172+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
173173
<argument type="service" id="validator" />
174174
</service>
175175
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
176-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
176+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
177177
</service>
178178
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
179-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
179+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
180180
</service>
181181
</services>
182182
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</service>
1212

1313
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
14-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
14+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
1515
<argument type="service" id="security.csrf.token_manager" />
1616
<argument>%form.type_extension.csrf.enabled%</argument>
1717
<argument>%form.type_extension.csrf.field_name%</argument>

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<!-- DataCollectorTypeExtension -->
2323
<service id="form.type_extension.form.data_collector" class="%form.type_extension.form.data_collector.class%">
24-
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
24+
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
2525
<argument type="service" id="data_collector.form" />
2626
</service>
2727

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php

+45-12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public function testAddTaggedTypes()
6868
), $extDefinition->getArgument(1));
6969
}
7070

71+
/**
72+
* @group legacy
73+
*/
7174
public function testUseCustomAliasIfSet()
7275
{
7376
$container = new ContainerBuilder();
@@ -107,25 +110,20 @@ public function testAddTaggedTypeExtensions()
107110
$container = new ContainerBuilder();
108111
$container->addCompilerPass(new FormPass());
109112

110-
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
111-
$extDefinition->setArguments(array(
113+
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array(
112114
new Reference('service_container'),
113115
array(),
114116
array(),
115117
array(),
116118
));
117119

118-
$definition1 = new Definition('stdClass');
119-
$definition1->addTag('form.type_extension', array('alias' => 'type1'));
120-
$definition2 = new Definition('stdClass');
121-
$definition2->addTag('form.type_extension', array('alias' => 'type1'));
122-
$definition3 = new Definition('stdClass');
123-
$definition3->addTag('form.type_extension', array('alias' => 'type2'));
124-
125120
$container->setDefinition('form.extension', $extDefinition);
126-
$container->setDefinition('my.type_extension1', $definition1);
127-
$container->setDefinition('my.type_extension2', $definition2);
128-
$container->setDefinition('my.type_extension3', $definition3);
121+
$container->register('my.type_extension1', 'stdClass')
122+
->addTag('form.type_extension', array('extended_type' => 'type1'));
123+
$container->register('my.type_extension2', 'stdClass')
124+
->addTag('form.type_extension', array('extended_type' => 'type1'));
125+
$container->register('my.type_extension3', 'stdClass')
126+
->addTag('form.type_extension', array('extended_type' => 'type2'));
129127

130128
$container->compile();
131129

@@ -142,6 +140,41 @@ public function testAddTaggedTypeExtensions()
142140
), $extDefinition->getArgument(2));
143141
}
144142

143+
/**
144+
* @group legacy
145+
*/
146+
public function testAliasOptionForTaggedTypeExtensions()
147+
{
148+
$container = new ContainerBuilder();
149+
$container->addCompilerPass(new FormPass());
150+
151+
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array(
152+
new Reference('service_container'),
153+
array(),
154+
array(),
155+
array(),
156+
));
157+
158+
$container->setDefinition('form.extension', $extDefinition);
159+
$container->register('my.type_extension1', 'stdClass')
160+
->addTag('form.type_extension', array('alias' => 'type1'));
161+
$container->register('my.type_extension2', 'stdClass')
162+
->addTag('form.type_extension', array('alias' => 'type2'));
163+
164+
$container->compile();
165+
166+
$extDefinition = $container->getDefinition('form.extension');
167+
168+
$this->assertSame(array(
169+
'type1' => array(
170+
'my.type_extension1',
171+
),
172+
'type2' => array(
173+
'my.type_extension2',
174+
),
175+
), $extDefinition->getArgument(2));
176+
}
177+
145178
public function testAddTaggedGuessers()
146179
{
147180
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)