Skip to content

Commit 3a62981

Browse files
committed
Deprecated alias setting of form tags
1 parent 1d5557f commit 3a62981

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function process(ContainerBuilder $container)
3434
$types = array();
3535

3636
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
37+
// Support type access by FQCN
38+
$serviceDefinition = $container->getDefinition($serviceId);
39+
$types[$serviceDefinition->getClass()] = $serviceId;
40+
3741
// The following if-else block is deprecated and will be removed
3842
// in Symfony 3.0
3943
// Deprecation errors are triggered in the form registry
@@ -42,22 +46,22 @@ public function process(ContainerBuilder $container)
4246
} else {
4347
$types[$serviceId] = $serviceId;
4448
}
45-
46-
// Support type access by FQCN
47-
$serviceDefinition = $container->getDefinition($serviceId);
48-
$types[$serviceDefinition->getClass()] = $serviceId;
4949
}
5050

5151
$definition->replaceArgument(1, $types);
5252

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 = $serviceId;
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+
}
5963

60-
$typeExtensions[$alias][] = $serviceId;
64+
$typeExtensions[$extendedType][] = $serviceId;
6165
}
6266

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

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

Lines changed: 45 additions & 3 deletions
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();
@@ -116,11 +119,11 @@ public function testAddTaggedTypeExtensions()
116119
));
117120

118121
$definition1 = new Definition('stdClass');
119-
$definition1->addTag('form.type_extension', array('alias' => 'type1'));
122+
$definition1->addTag('form.type_extension', array('extended_type' => 'type1'));
120123
$definition2 = new Definition('stdClass');
121-
$definition2->addTag('form.type_extension', array('alias' => 'type1'));
124+
$definition2->addTag('form.type_extension', array('extended_type' => 'type1'));
122125
$definition3 = new Definition('stdClass');
123-
$definition3->addTag('form.type_extension', array('alias' => 'type2'));
126+
$definition3->addTag('form.type_extension', array('extended_type' => 'type2'));
124127

125128
$container->setDefinition('form.extension', $extDefinition);
126129
$container->setDefinition('my.type_extension1', $definition1);
@@ -142,6 +145,45 @@ public function testAddTaggedTypeExtensions()
142145
), $extDefinition->getArgument(2));
143146
}
144147

148+
/**
149+
* @group legacy
150+
*/
151+
public function testAliasOptionForTaggedTypeExtensions()
152+
{
153+
$container = new ContainerBuilder();
154+
$container->addCompilerPass(new FormPass());
155+
156+
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
157+
$extDefinition->setArguments(array(
158+
new Reference('service_container'),
159+
array(),
160+
array(),
161+
array(),
162+
));
163+
164+
$definition1 = new Definition('stdClass');
165+
$definition1->addTag('form.type_extension', array('alias' => 'type1'));
166+
$definition2 = new Definition('stdClass');
167+
$definition2->addTag('form.type_extension', array('alias' => 'type2'));
168+
169+
$container->setDefinition('form.extension', $extDefinition);
170+
$container->setDefinition('my.type_extension1', $definition1);
171+
$container->setDefinition('my.type_extension2', $definition2);
172+
173+
$container->compile();
174+
175+
$extDefinition = $container->getDefinition('form.extension');
176+
177+
$this->assertSame(array(
178+
'type1' => array(
179+
'my.type_extension1',
180+
),
181+
'type2' => array(
182+
'my.type_extension2',
183+
),
184+
), $extDefinition->getArgument(2));
185+
}
186+
145187
public function testAddTaggedGuessers()
146188
{
147189
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)