Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d048496

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

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,35 @@ 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->findDefinition($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
4044
if (isset($tag[0]['alias'])) {
45+
@trigger_error(sprintf('The alias option of the form.type tag is deprecated since version 2.8 and will be removed in 3.0. Use the fully-qualified type class name "%s" instead.', $serviceDefinition->getClass()));
4146
$types[$tag[0]['alias']] = $serviceId;
4247
} else {
4348
$types[$serviceId] = $serviceId;
4449
}
45-
46-
// Support type access by FQCN
47-
$serviceDefinition = $container->getDefinition($serviceId);
48-
$types[$serviceDefinition->getClass()] = $serviceId;
4950
}
5051

5152
$definition->replaceArgument(1, $types);
5253

5354
$typeExtensions = array();
5455

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

60-
$typeExtensions[$alias][] = $serviceId;
65+
$typeExtensions[$extendedType][] = $serviceId;
6166
}
6267

6368
$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)