From edc4889461a47415c3ab337689bb63ee92675d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 Apr 2017 23:07:49 +0200 Subject: [PATCH] move service form.type definition to new file + introduce date type --- DependencyInjection/ChillMainExtension.php | 1 + Form/Type/ChillDateType.php | 47 +++++++++++ Resources/config/services.yml | 86 -------------------- Resources/config/services/form.yml | 93 ++++++++++++++++++++++ 4 files changed, 141 insertions(+), 86 deletions(-) create mode 100644 Form/Type/ChillDateType.php create mode 100644 Resources/config/services/form.yml diff --git a/DependencyInjection/ChillMainExtension.php b/DependencyInjection/ChillMainExtension.php index 531716c35..c2f63761f 100644 --- a/DependencyInjection/ChillMainExtension.php +++ b/DependencyInjection/ChillMainExtension.php @@ -91,6 +91,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $loader->load('services/repositories.yml'); $loader->load('services/pagination.yml'); $loader->load('services/export.yml'); + $loader->load('services/form.yml'); } diff --git a/Form/Type/ChillDateType.php b/Form/Type/ChillDateType.php new file mode 100644 index 000000000..2f5a6945c --- /dev/null +++ b/Form/Type/ChillDateType.php @@ -0,0 +1,47 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\Form\Type; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\DateType; +use Symfony\Component\OptionsResolver\OptionsResolver; + +/** + * Display the date in a date picker. + * + * Extends the symfony `Symfony\Component\Form\Extension\Core\Type\DateType` + * to automatically create a date picker. + * + * @author Julien Fastré + */ +class ChillDateType extends AbstractType +{ + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('widget', 'single_text') + ->setDefault('attr', [ 'class' => 'datepicker' ]) + ->setDefault('format', 'dd-MM-yyyy') + ; + } + + public function getParent() + { + return DateType::class; + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index ad81a5738..33b64df34 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -36,15 +36,6 @@ services: tags: - { name: twig.extension } - chill.main.form.type.translatable.string: - class: Chill\MainBundle\Form\Type\TranslatableStringFormType - arguments: - - "%chill_main.available_languages%" - #- "%framework.translator.fallback%" - - "@translator.default" - tags: - - { name: form.type, alias: translatable_string } - chill.main.helper.translatable_string: class: Chill\MainBundle\Templating\TranslatableStringHelper arguments: @@ -70,38 +61,6 @@ services: tags: - { name: twig.extension } - chill.main.form.type.select2choice: - class: Chill\MainBundle\Form\Type\Select2ChoiceType - tags: - - {name: form.type, alias: select2_choice} - - chill.main.form.type.select2entity: - class: Chill\MainBundle\Form\Type\Select2EntityType - tags: - - {name: form.type, alias: select2_entity } - - chill.main.form.type.select2country: - class: Chill\MainBundle\Form\Type\Select2CountryType - arguments: - - "@request_stack" - - "@doctrine.orm.entity_manager" - tags: - - { name: form.type, alias: select2_chill_country } - - chill.main.form.type.select2language: - class: Chill\MainBundle\Form\Type\Select2LanguageType - arguments: - - "@request_stack" - - "@doctrine.orm.entity_manager" - tags: - - { name: form.type, alias: select2_chill_language } - chill.main.form.type.center: - class: Chill\MainBundle\Form\Type\CenterType - arguments: - - "@security.token_storage" - - "@chill.main.form.data_transformer.center_transformer" - tags: - - { name: form.type, alias: center } chill.main.form.data_transformer.center_transformer: class: Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer arguments: @@ -125,14 +84,6 @@ services: chill.main.role_provider: class: Chill\MainBundle\Security\RoleProvider - chill.main.form.type.composed_role_scope: - class: Chill\MainBundle\Form\Type\ComposedRoleScopeType - arguments: - - "@chill.main.helper.translatable_string" - - "@chill.main.role_provider" - tags: - - { name: form.type, alias: composed_role_scope } - chill.main.validator.role_scope_scope_presence: class: Chill\MainBundle\Validation\Validator\RoleScopeScopePresence arguments: @@ -141,13 +92,6 @@ services: - "@translator" tags: - { name: validator.constraint_validator, alias: 'role_scope_scope_presence' } - - chill.main.form.type.postal_code_type: - class: Chill\MainBundle\Form\Type\PostalCodeType - arguments: - - "@chill.main.helper.translatable_string" - tags: - - { name: form.type } chill.main.export_manager: class: Chill\MainBundle\Export\ExportManager @@ -157,33 +101,3 @@ services: - "@security.authorization_checker" - "@chill.main.security.authorization.helper" - "@security.token_storage" - - chill.main.form.type.export: - class: Chill\MainBundle\Form\Type\Export\ExportType - arguments: - - "@chill.main.export_manager" - tags: - - { name: form.type } - - chill.main.form.pick_formatter_type: - class: Chill\MainBundle\Form\Type\Export\PickFormatterType - arguments: - - "@chill.main.export_manager" - tags: - - { name: form.type } - - chill.main.form.pick_centers_type: - class: Chill\MainBundle\Form\Type\Export\PickCenterType - arguments: - - "@security.token_storage" - - "@chill.main.export_manager" - - "@chill.main.security.authorization.helper" - tags: - - { name: form.type } - - chill.main.form.formatter_type: - class: Chill\MainBundle\Form\Type\Export\FormatterType - arguments: - - "@chill.main.export_manager" - tags: - - { name: form.type } diff --git a/Resources/config/services/form.yml b/Resources/config/services/form.yml new file mode 100644 index 000000000..03f244e1d --- /dev/null +++ b/Resources/config/services/form.yml @@ -0,0 +1,93 @@ +services: + chill.main.form.type.translatable.string: + class: Chill\MainBundle\Form\Type\TranslatableStringFormType + arguments: + - "%chill_main.available_languages%" + #- "%framework.translator.fallback%" + - "@translator.default" + tags: + - { name: form.type, alias: translatable_string } + + chill.main.form.type.select2choice: + class: Chill\MainBundle\Form\Type\Select2ChoiceType + tags: + - {name: form.type, alias: select2_choice} + + chill.main.form.type.select2entity: + class: Chill\MainBundle\Form\Type\Select2EntityType + tags: + - {name: form.type, alias: select2_entity } + + chill.main.form.type.select2country: + class: Chill\MainBundle\Form\Type\Select2CountryType + arguments: + - "@request_stack" + - "@doctrine.orm.entity_manager" + tags: + - { name: form.type, alias: select2_chill_country } + + chill.main.form.type.select2language: + class: Chill\MainBundle\Form\Type\Select2LanguageType + arguments: + - "@request_stack" + - "@doctrine.orm.entity_manager" + tags: + - { name: form.type, alias: select2_chill_language } + chill.main.form.type.center: + class: Chill\MainBundle\Form\Type\CenterType + arguments: + - "@security.token_storage" + - "@chill.main.form.data_transformer.center_transformer" + tags: + - { name: form.type, alias: center } + + chill.main.form.type.composed_role_scope: + class: Chill\MainBundle\Form\Type\ComposedRoleScopeType + arguments: + - "@chill.main.helper.translatable_string" + - "@chill.main.role_provider" + tags: + - { name: form.type, alias: composed_role_scope } + + + chill.main.form.type.postal_code_type: + class: Chill\MainBundle\Form\Type\PostalCodeType + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } + + chill.main.form.type.export: + class: Chill\MainBundle\Form\Type\Export\ExportType + arguments: + - "@chill.main.export_manager" + tags: + - { name: form.type } + + chill.main.form.pick_formatter_type: + class: Chill\MainBundle\Form\Type\Export\PickFormatterType + arguments: + - "@chill.main.export_manager" + tags: + - { name: form.type } + + chill.main.form.pick_centers_type: + class: Chill\MainBundle\Form\Type\Export\PickCenterType + arguments: + - "@security.token_storage" + - "@chill.main.export_manager" + - "@chill.main.security.authorization.helper" + tags: + - { name: form.type } + + chill.main.form.formatter_type: + class: Chill\MainBundle\Form\Type\Export\FormatterType + arguments: + - "@chill.main.export_manager" + tags: + - { name: form.type } + + chill.main.form.date_type: + class: Chill\MainBundle\Form\Type\ChillDateType + tags: + - { name: form.type } \ No newline at end of file