Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Deprecate the form mapping feature
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Nov 5, 2017
1 parent d389fcc commit 7261171
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 74 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Compiler/FormFactoryCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/SonataCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
72 changes: 0 additions & 72 deletions Resources/doc/reference/form_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
namespace Sonata\AdminBundle;
use Sonata\CoreBundle\Form\FormHelper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class SonataAdminBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$this->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
----------------------------

Expand Down
7 changes: 5 additions & 2 deletions Tests/DependencyInjection/SonataCoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand All @@ -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'
);
Expand Down
14 changes: 14 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -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
=======================
Expand Down

0 comments on commit 7261171

Please sign in to comment.