From 7261171cd19df1437cdb07576836a3c6cce9e75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 5 Nov 2017 20:38:04 +0100 Subject: [PATCH] Deprecate the form mapping feature --- .../Compiler/FormFactoryCompilerPass.php | 3 + DependencyInjection/SonataCoreExtension.php | 4 ++ Resources/doc/reference/form_types.rst | 72 ------------------- .../SonataCoreExtensionTest.php | 7 +- UPGRADE-3.x.md | 14 ++++ 5 files changed, 26 insertions(+), 74 deletions(-) diff --git a/DependencyInjection/Compiler/FormFactoryCompilerPass.php b/DependencyInjection/Compiler/FormFactoryCompilerPass.php index 8980beb2..08fb71de 100644 --- a/DependencyInjection/Compiler/FormFactoryCompilerPass.php +++ b/DependencyInjection/Compiler/FormFactoryCompilerPass.php @@ -14,6 +14,9 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * @deprecated disable this compiler pass + */ class FormFactoryCompilerPass extends FormPass { /** diff --git a/DependencyInjection/SonataCoreExtension.php b/DependencyInjection/SonataCoreExtension.php index 5e2f7465..9bafa65e 100644 --- a/DependencyInjection/SonataCoreExtension.php +++ b/DependencyInjection/SonataCoreExtension.php @@ -116,6 +116,10 @@ public function configureFormFactory(ContainerBuilder $container, array $config) return; } + @trigger_error( + 'Relying on the form mapping feature is deprecated since 3.x and will be removed in 4.0. Please set the "sonata_core.form.mapping.enabled" configuration node to false to avoid this message.', + E_USER_DEPRECATED + ); $container->setParameter('sonata.core.form.mapping.type', $config['form']['mapping']['type']); $container->setParameter('sonata.core.form.mapping.extension', $config['form']['mapping']['extension']); diff --git a/Resources/doc/reference/form_types.rst b/Resources/doc/reference/form_types.rst index 7640a559..038f4eb8 100644 --- a/Resources/doc/reference/form_types.rst +++ b/Resources/doc/reference/form_types.rst @@ -6,78 +6,6 @@ Form Types The bundle comes with some handy form types. - -Symfony3 Supports ------------------ - -In order to help the migration path toward Symfony3, the bundle restores the Symfony2.X behavior of string code usage for the form type declaration. -Each bundles can register a mapping with Symfony3 boot. - -.. code-block:: php - - registerFormMapping(); - } - - /** - * {@inheritdoc} - */ - public function boot() - { - $this->registerFormMapping(); - } - - /** - * Register form mapping information - */ - public function registerFormMapping() - { - FormHelper::registerFormTypeMapping(array( - 'sonata_type_admin' => 'Sonata\AdminBundle\Form\Type\AdminType', // the form mapping - )); - - FormHelper::registerFormExtensionMapping('choice', array( // the extended mapping for the choice type - 'sonata.admin.form.extension.choice', - )); - } - } - -You can either alter your bundle to configure these mappings or you can add the mapping as configuration settings. Values provided in configuration will overwrite default values: - -.. code-block: yaml - - sonata_core: - form: - mapping: - enabled: true # (default value) - type: - sonata_type_admin: Sonata\AdminBundle\Form\Type\AdminType - - extension: - choice: - - sonata.admin.form.extension.choice - -If you are lazy, you can get the mapping with the command: - -.. code-block: yaml - - app/console sonata:core:form-mapping -f yaml|php - - - DoctrineORMSerializationType ---------------------------- diff --git a/Tests/DependencyInjection/SonataCoreExtensionTest.php b/Tests/DependencyInjection/SonataCoreExtensionTest.php index ac551aee..0cb6716a 100644 --- a/Tests/DependencyInjection/SonataCoreExtensionTest.php +++ b/Tests/DependencyInjection/SonataCoreExtensionTest.php @@ -18,7 +18,7 @@ class SonataCoreExtensionTest extends AbstractExtensionTestCase { public function testAfterLoadingTheWrappingParameterIsSet() { - $this->load(); + $this->load(['form' => ['mapping' => ['enabled' => false]]]); $this->assertContainerBuilderHasParameter( 'sonata.core.form_type' ); @@ -32,7 +32,10 @@ public function testAfterLoadingTheWrappingParameterIsSet() public function testHorizontalFormTypeMeansNoWrapping() { - $this->load(['form_type' => 'horizontal']); + $this->load([ + 'form' => ['mapping' => ['enabled' => false]], + 'form_type' => 'horizontal' + ]); $this->assertContainerBuilderHasParameter( 'sonata.core.form_type' ); diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 21ef6656..f903927e 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -1,6 +1,20 @@ UPGRADE 3.x =========== +UPGRADE FROM 3.6 to 3.7 +======================= +Using the form mapping feature is now deprecated. You should use FQCNs +everywhere form names are used, and disable this feature with the following +piece of configuration: + +```yaml +# config.yml +sonata_core: + form: + mapping: + enabled: false +``` + UPGRADE FROM 3.4 to 3.5 =======================