diff --git a/src/Bridge/Symfony/DependencyInjection/SonataFormExtension.php b/src/Bridge/Symfony/DependencyInjection/SonataFormExtension.php index 9da3517c..db1cdc6b 100644 --- a/src/Bridge/Symfony/DependencyInjection/SonataFormExtension.php +++ b/src/Bridge/Symfony/DependencyInjection/SonataFormExtension.php @@ -19,7 +19,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** @@ -47,10 +47,10 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('date.xml'); - $loader->load('form_types.xml'); - $loader->load('validator.xml'); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('date.php'); + $loader->load('form_types.php'); + $loader->load('validator.php'); $container->setParameter('sonata.form.form_type', $config['form_type']); diff --git a/src/Bridge/Symfony/Resources/config/date.php b/src/Bridge/Symfony/Resources/config/date.php new file mode 100644 index 00000000..de005d9e --- /dev/null +++ b/src/Bridge/Symfony/Resources/config/date.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\Form\Date\MomentFormatConverter; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + $containerConfigurator->services() + + ->set('sonata.form.date.moment_format_converter', MomentFormatConverter::class); +}; diff --git a/src/Bridge/Symfony/Resources/config/date.xml b/src/Bridge/Symfony/Resources/config/date.xml deleted file mode 100644 index 539bc77b..00000000 --- a/src/Bridge/Symfony/Resources/config/date.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/Bridge/Symfony/Resources/config/form_types.php b/src/Bridge/Symfony/Resources/config/form_types.php new file mode 100644 index 00000000..c94e52cb --- /dev/null +++ b/src/Bridge/Symfony/Resources/config/form_types.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\Form\Type\BooleanType; +use Sonata\Form\Type\CollectionType; +use Sonata\Form\Type\DatePickerType; +use Sonata\Form\Type\DateRangePickerType; +use Sonata\Form\Type\DateRangeType; +use Sonata\Form\Type\DateTimePickerType; +use Sonata\Form\Type\DateTimeRangePickerType; +use Sonata\Form\Type\DateTimeRangeType; +use Sonata\Form\Type\EqualType; +use Sonata\Form\Type\ImmutableArrayType; +use Symfony\Component\Config\Definition\BaseNode; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + // BC layer for deprecation messages for symfony/config < 5.1 + $getDeprecationParameters = static function (string $message, string $version): array { + if (method_exists(BaseNode::class, 'getDeprecation')) { + return [ + 'sonata-project/form-extensions', + $version, + $message, + ]; + } + + return [$message]; + }; + + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + // Use "param" function for creating references to parameters when dropping support for Symfony 5.1 + $containerConfigurator->services() + + ->set('sonata.form.type.array', ImmutableArrayType::class) + ->tag('form.type', ['alias' => 'sonata_type_immutable_array']) + + ->set('sonata.form.type.boolean', BooleanType::class) + ->tag('form.type', ['alias' => 'sonata_type_boolean']) + + ->set('sonata.form.type.collection', CollectionType::class) + ->tag('form.type', ['alias' => 'sonata_type_collection']) + + ->set('sonata.form.type.date_range', DateRangeType::class) + ->tag('form.type', ['alias' => 'sonata_type_date_range']) + ->args([ + new ReferenceConfigurator('translator'), + ]) + + ->set('sonata.form.type.datetime_range', DateTimeRangeType::class) + ->tag('form.type', ['alias' => 'sonata_type_datetime_range']) + ->args([ + new ReferenceConfigurator('translator'), + ]) + + ->set('sonata.form.type.date_picker', DatePickerType::class) + ->tag('kernel.locale_aware') + ->tag('form.type', ['alias' => 'sonata_type_date_picker']) + ->args([ + new ReferenceConfigurator('sonata.form.date.moment_format_converter'), + new ReferenceConfigurator('translator'), + '%kernel.default_locale%', + ]) + + ->set('sonata.form.type.datetime_picker', DateTimePickerType::class) + ->tag('kernel.locale_aware') + ->tag('form.type', ['alias' => 'sonata_type_datetime_picker']) + ->args([ + new ReferenceConfigurator('sonata.form.date.moment_format_converter'), + new ReferenceConfigurator('translator'), + '%kernel.default_locale%', + ]) + + ->set('sonata.form.type.date_range_picker', DateRangePickerType::class) + ->tag('form.type', ['alias' => 'sonata_type_date_range_picker']) + ->args([ + new ReferenceConfigurator('translator'), + ]) + + ->set('sonata.form.type.datetime_range_picker', DateTimeRangePickerType::class) + ->tag('form.type', ['alias' => 'sonata_type_datetime_range_picker']) + ->args([ + new ReferenceConfigurator('translator'), + ]) + + ->set('sonata.form.type.equal', EqualType::class) + ->tag('form.type', ['alias' => 'sonata_type_equal']) + ->deprecate(...$getDeprecationParameters( + 'The "%service_id%" service is deprecated since sonata-project/form-extensions 1.2 and will be removed in 2.0. Use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType instead', + '1.2' + )) + ->args([ + new ReferenceConfigurator('translator'), + ]); +}; diff --git a/src/Bridge/Symfony/Resources/config/form_types.xml b/src/Bridge/Symfony/Resources/config/form_types.xml deleted file mode 100644 index 494dc60d..00000000 --- a/src/Bridge/Symfony/Resources/config/form_types.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - %kernel.default_locale% - - - - - - - %kernel.default_locale% - - - - - - - - - - - The "%service_id%" service is deprecated since sonata-project/form-extensions 1.2 and will be removed in 2.0. Use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType instead - - - - - diff --git a/src/Bridge/Symfony/Resources/config/validator.php b/src/Bridge/Symfony/Resources/config/validator.php new file mode 100644 index 00000000..5a730fc6 --- /dev/null +++ b/src/Bridge/Symfony/Resources/config/validator.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\Form\Validator\InlineValidator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + $containerConfigurator->services() + // Use "service" function for creating references to services when dropping support for Symfony 4.4 + ->set('sonata.form.validator.inline', InlineValidator::class) + ->tag('validator.constraint_validator', [ + 'alias' => 'sonata.form.validator.inline', + ]) + ->args([ + new ReferenceConfigurator('service_container'), + new ReferenceConfigurator('validator.validator_factory'), + ]); +}; diff --git a/src/Bridge/Symfony/Resources/config/validator.xml b/src/Bridge/Symfony/Resources/config/validator.xml deleted file mode 100644 index 2cee884e..00000000 --- a/src/Bridge/Symfony/Resources/config/validator.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - -