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

Commit

Permalink
Merge 7ebdaa6 into a256555
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed May 27, 2020
2 parents a256555 + 7ebdaa6 commit a58d5fc
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 70 deletions.
158 changes: 158 additions & 0 deletions src/CoreBundle/DependencyInjection/Compiler/FormCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @deprecated since sonata-project/core-bundle 3.19, to be removed in 4.0.
*/
class FormCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$this->registerDateAliases($container);
$this->registerFormTypeAlias($container);
$this->forceUserToMoveConfig($container);
}

public function registerDateAliases(ContainerBuilder $container)
{
$momentFormatConventerAlias = $container
->setAlias('sonata.core.date.moment_format_converter', 'sonata.form.date.moment_format_converter')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);
}

public function registerFormTypeAlias(ContainerBuilder $container)
{
$arrayTypeAlias = $container
->setAlias('sonata.core.form.type.array', 'sonata.form.type.array')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$boolenTypeAlias = $container
->setAlias('sonata.core.form.type.boolean', 'sonata.form.type.boolean')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$collectionTypeAlias = $container
->setAlias('sonata.core.form.type.collection', 'sonata.form.type.collection')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$dateRangeAlias = $container
->setAlias('sonata.core.form.type.date_range', 'sonata.form.type.date_range')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$datetimeRangeAlias = $container
->setAlias('sonata.core.form.type.datetime_range', 'sonata.form.type.datetime_range')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$datePickerAlias = $container
->setAlias('sonata.core.form.type.date_picker', 'sonata.form.type.date_picker')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$datetimePickerAlias = $container
->setAlias('sonata.core.form.type.datetime_picker', 'sonata.form.type.datetime_picker')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$dateRangePickerAlias = $container
->setAlias('sonata.core.form.type.date_range_picker', 'sonata.form.type.date_range_picker')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$datetimeRangePickerAlias = $container
->setAlias('sonata.core.form.type.datetime_range_picker', 'sonata.form.type.datetime_range_picker')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$equalTypeAlias = $container
->setAlias('sonata.core.form.type.equal', 'sonata.form.type.equal')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);
}

public function forceUserToMoveConfig(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');

if (!isset($bundles['SonataFormBundle'])) {
return;
}

$defaultForm = [
'mapping' => [
'enabled' => true,
'type' => [],
'extension' => [],
],
];
$defaultSerializer = [
'formats' => [
0 => 'json',
1 => 'xml',
2 => 'yml',
],
];

if ($container->getParameter('sonata.core.form') !== $defaultForm) {
throw new \Exception('Move bundle config from sonata_core.form to sonata_form.form');
}

if ($container->getParameter('sonata.core.serializer') !== $defaultSerializer) {
throw new \Exception('Move bundle config from sonata_core.serializer to sonata_form.serializer');
}
}
}
107 changes: 107 additions & 0 deletions src/CoreBundle/DependencyInjection/Compiler/TwigCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @deprecated since sonata-project/core-bundle 3.19, to be removed in 4.0.
*/
class TwigCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$this->registerFlashAliases($container);
$this->registerTwigAliases($container);
$this->forceUserToMoveConfig($container);
}

public function registerFlashAliases(ContainerBuilder $container)
{
$flashManagerAlias = $container
->setAlias('sonata.core.flashmessage.manager', 'sonata.twig.flashmessage.manager')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$flashRuntimeAlias = $container
->setAlias('sonata.core.flashmessage.twig.runtime', 'sonata.twig.flashmessage.twig.runtime')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$flashExtensionAlias = $container
->setAlias('sonata.core.flashmessage.twig.extension', 'sonata.twig.flashmessage.twig.extension')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);
}

public function registerTwigAliases(ContainerBuilder $container)
{
$extensionWrapping = $container
->setAlias('sonata.core.twig.extension.wrapping', 'sonata.twig.extension.wrapping')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$runtimeStatus = $container
->setAlias('sonata.core.twig.status_runtime', 'sonata.twig.status_runtime')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$extensionDeprecatedTemplate = $container
->setAlias('sonata.core.twig.deprecated_template_extension', 'sonata.twig.deprecated_template_extension')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);

$extensionTemplate = $container
->setAlias('sonata.core.twig.template_extension', 'sonata.twig.template_extension')
->setPublic(true)
->setDeprecated(
true,
'The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.'
);
}

public function forceUserToMoveConfig(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');

if (!isset($bundles['SonataTwigBundle'])) {
return;
}

if (!empty($container->getParameter('sonata.core.flashmessage'))) {
throw new \Exception('Move bundle config from sonata_core.flashmessage to sonata_twig.flashmessage');
}
}
}
10 changes: 6 additions & 4 deletions src/CoreBundle/DependencyInjection/SonataCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('commands.xml');
$loader->load('core.xml');
$loader->load('date.xml');
$loader->load('flash.xml');
$loader->load('form_types.xml');
$loader->load('model_adapter.xml');
$loader->load('twig.xml');
$loader->load('validator.xml');
$loader->load('twig.xml');

if (!isset($bundles['SonataFormBundle'])) {
$loader->load('form/date.xml');
Expand All @@ -110,10 +108,14 @@ public function load(array $configs, ContainerBuilder $container)
if (!isset($bundles['SonataTwigBundle'])) {
$loader->load('twig/flash.xml');
$loader->load('twig/twig.xml');

$this->registerFlashTypes($container, $config);
}

$this->registerFlashTypes($container, $config);
$container->setParameter('sonata.core.form', $config['form']);
$container->setParameter('sonata.core.form_type', $config['form_type']);
$container->setParameter('sonata.core.flashmessage', $config['flashmessage']);
$container->setParameter('sonata.core.serializer', $config['serializer']);

$this->configureFormFactory($container, $config);
if (\PHP_VERSION_ID < 70000) {
Expand Down
8 changes: 0 additions & 8 deletions src/CoreBundle/Resources/config/date.xml

This file was deleted.

14 changes: 0 additions & 14 deletions src/CoreBundle/Resources/config/flash.xml

This file was deleted.

30 changes: 0 additions & 30 deletions src/CoreBundle/Resources/config/form_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,5 @@
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0.</deprecated>
<tag name="form.type" alias="sonata_type_color"/>
</service>
<service id="sonata.core.form.type.array" alias="sonata.form.type.array" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.boolean" alias="sonata.form.type.boolean" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.collection" alias="sonata.form.type.collection" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.date_range" alias="sonata.form.type.date_range" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.datetime_range" alias="sonata.form.type.datetime_range" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.date_picker" alias="sonata.form.type.date_picker" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.datetime_picker" alias="sonata.form.type.datetime_picker" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.date_range_picker" alias="sonata.form.type.date_range_picker" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.datetime_range_picker" alias="sonata.form.type.datetime_range_picker" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.equal" class="Sonata\Form\Type\EqualType" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
</services>
</container>
12 changes: 0 additions & 12 deletions src/CoreBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.core.twig.extension.wrapping" alias="sonata.twig.extension.wrapping">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.twig.extension.text" class="Sonata\CoreBundle\Twig\Extension\DeprecatedTextExtension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0.</deprecated>
<tag name="twig.extension"/>
</service>
<service id="sonata.core.twig.status_runtime" alias="sonata.twig.status_runtime">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.twig.status_extension" class="Sonata\CoreBundle\Twig\Extension\StatusExtension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "sonata.twig.status_extension" instead.</deprecated>
<tag name="twig.extension"/>
</service>
<service id="sonata.core.twig.deprecated_template_extension" alias="sonata.twig.deprecated_template_extension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.twig.template_extension" alias="sonata.twig.template_extension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.19 and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
</services>
</container>
Loading

0 comments on commit a58d5fc

Please sign in to comment.