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
This commit is contained in:
commit
e7325b721e
@ -235,6 +235,23 @@ Form
|
|||||||
match the type returned by `getExtendedType` is now forbidden. Fix your
|
match the type returned by `getExtendedType` is now forbidden. Fix your
|
||||||
implementation to define the right type.
|
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
|
Translator
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ CHANGELOG
|
|||||||
2.8.0
|
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
|
* Deprecated the Shell
|
||||||
|
|
||||||
2.7.0
|
2.7.0
|
||||||
|
@ -53,11 +53,18 @@ class FormPass implements CompilerPassInterface
|
|||||||
$typeExtensions = array();
|
$typeExtensions = array();
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) {
|
foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) {
|
||||||
$alias = isset($tag[0]['alias'])
|
$extendedType = null;
|
||||||
? $tag[0]['alias']
|
if (isset($tag[0]['extended_type'])) {
|
||||||
: $serviceId;
|
$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);
|
$definition->replaceArgument(2, $typeExtensions);
|
||||||
|
@ -155,7 +155,7 @@
|
|||||||
<!-- FormTypeHttpFoundationExtension -->
|
<!-- FormTypeHttpFoundationExtension -->
|
||||||
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\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" />
|
<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>
|
</service>
|
||||||
|
|
||||||
<!-- HttpFoundationRequestHandler -->
|
<!-- HttpFoundationRequestHandler -->
|
||||||
@ -169,14 +169,14 @@
|
|||||||
|
|
||||||
<!-- FormTypeValidatorExtension -->
|
<!-- FormTypeValidatorExtension -->
|
||||||
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\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" />
|
<argument type="service" id="validator" />
|
||||||
</service>
|
</service>
|
||||||
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
|
<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>
|
||||||
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
|
<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>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
|
<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 type="service" id="security.csrf.token_manager" />
|
||||||
<argument>%form.type_extension.csrf.enabled%</argument>
|
<argument>%form.type_extension.csrf.enabled%</argument>
|
||||||
<argument>%form.type_extension.csrf.field_name%</argument>
|
<argument>%form.type_extension.csrf.field_name%</argument>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<!-- DataCollectorTypeExtension -->
|
<!-- DataCollectorTypeExtension -->
|
||||||
<service id="form.type_extension.form.data_collector" class="%form.type_extension.form.data_collector.class%">
|
<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" />
|
<argument type="service" id="data_collector.form" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -68,6 +68,9 @@ class FormPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
), $extDefinition->getArgument(1));
|
), $extDefinition->getArgument(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
public function testUseCustomAliasIfSet()
|
public function testUseCustomAliasIfSet()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
@ -107,25 +110,20 @@ class FormPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->addCompilerPass(new FormPass());
|
$container->addCompilerPass(new FormPass());
|
||||||
|
|
||||||
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
|
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension', array(
|
||||||
$extDefinition->setArguments(array(
|
|
||||||
new Reference('service_container'),
|
new Reference('service_container'),
|
||||||
array(),
|
array(),
|
||||||
array(),
|
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('form.extension', $extDefinition);
|
||||||
$container->setDefinition('my.type_extension1', $definition1);
|
$container->register('my.type_extension1', 'stdClass')
|
||||||
$container->setDefinition('my.type_extension2', $definition2);
|
->addTag('form.type_extension', array('extended_type' => 'type1'));
|
||||||
$container->setDefinition('my.type_extension3', $definition3);
|
$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();
|
$container->compile();
|
||||||
|
|
||||||
@ -142,6 +140,41 @@ class FormPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
), $extDefinition->getArgument(2));
|
), $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()
|
public function testAddTaggedGuessers()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user