Skip to content

Commit

Permalink
[2.8][Form] Deprecate alias tag option
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj authored and Tobion committed Oct 1, 2015
1 parent 5ad49c6 commit e3aa522
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 22 deletions.
17 changes: 17 additions & 0 deletions UPGRADE-2.8.md
Expand Up @@ -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
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension">
<tag name="form.type_extension" alias="text" />
</service>
```

After:
```xml
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension">
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\TextType" />
</service>
```

Translator
----------

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Expand Up @@ -155,7 +155,7 @@
<!-- FormTypeHttpFoundationExtension -->
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
<argument type="service" id="form.type_extension.form.request_handler" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
</service>

<!-- HttpFoundationRequestHandler -->
Expand All @@ -169,14 +169,14 @@

<!-- FormTypeValidatorExtension -->
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
<argument type="service" id="validator" />
</service>
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
</service>
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
</service>
</services>
</container>
Expand Up @@ -11,7 +11,7 @@
</service>

<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
<argument type="service" id="security.csrf.token_manager" />
<argument>%form.type_extension.csrf.enabled%</argument>
<argument>%form.type_extension.csrf.field_name%</argument>
Expand Down
Expand Up @@ -21,7 +21,7 @@

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

Expand Down
Expand Up @@ -68,6 +68,9 @@ public function testAddTaggedTypes()
), $extDefinition->getArgument(1));
}

/**
* @group legacy
*/
public function testUseCustomAliasIfSet()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down

0 comments on commit e3aa522

Please sign in to comment.