vendor/sonata-project/core-bundle/src/CoreBundle/SonataCoreBundle.php line 76

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\CoreBundle;
  12. use Nelmio\ApiDocBundle\Form\Extension\DescriptionFormTypeExtension;
  13. use Sonata\CoreBundle\DependencyInjection\Compiler\AdapterCompilerPass;
  14. use Sonata\CoreBundle\DependencyInjection\Compiler\FormFactoryCompilerPass;
  15. use Sonata\CoreBundle\DependencyInjection\Compiler\StatusRendererCompilerPass;
  16. use Sonata\CoreBundle\Form\FormHelper;
  17. use Sonata\CoreBundle\Form\Type\ColorSelectorType;
  18. use Sonata\CoreBundle\Form\Type\ColorType;
  19. use Sonata\CoreBundle\Form\Type\TranslatableChoiceType;
  20. use Sonata\Form\Type\BooleanType;
  21. use Sonata\Form\Type\CollectionType;
  22. use Sonata\Form\Type\DatePickerType;
  23. use Sonata\Form\Type\DateRangePickerType;
  24. use Sonata\Form\Type\DateRangeType;
  25. use Sonata\Form\Type\DateTimePickerType;
  26. use Sonata\Form\Type\DateTimeRangePickerType;
  27. use Sonata\Form\Type\DateTimeRangeType;
  28. use Sonata\Form\Type\EqualType;
  29. use Sonata\Form\Type\ImmutableArrayType;
  30. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  31. use Symfony\Component\DependencyInjection\ContainerBuilder;
  32. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  33. use Symfony\Component\Form\Extension\Core\Type\ButtonType;
  34. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  35. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  36. use Symfony\Component\Form\Extension\Core\Type\CollectionType as SymfonyCollectionType;
  37. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  38. use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
  39. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  40. use Symfony\Component\Form\Extension\Core\Type\DateType;
  41. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  42. use Symfony\Component\Form\Extension\Core\Type\FileType;
  43. use Symfony\Component\Form\Extension\Core\Type\FormType;
  44. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  45. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  46. use Symfony\Component\Form\Extension\Core\Type\LanguageType;
  47. use Symfony\Component\Form\Extension\Core\Type\LocaleType;
  48. use Symfony\Component\Form\Extension\Core\Type\MoneyType;
  49. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  50. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  51. use Symfony\Component\Form\Extension\Core\Type\PercentType;
  52. use Symfony\Component\Form\Extension\Core\Type\RadioType;
  53. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  54. use Symfony\Component\Form\Extension\Core\Type\ResetType;
  55. use Symfony\Component\Form\Extension\Core\Type\SearchType;
  56. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  57. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  58. use Symfony\Component\Form\Extension\Core\Type\TextType;
  59. use Symfony\Component\Form\Extension\Core\Type\TimeType;
  60. use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
  61. use Symfony\Component\Form\Extension\Core\Type\UrlType;
  62. use Symfony\Component\HttpKernel\Bundle\Bundle;
  63. /**
  64.  * @deprecated since sonata-project/core-bundle 3.19, to be removed in 4.0.
  65.  * Use
  66.  *  sonata-project/doctrine-extensions,
  67.  *  sonata-project/form-extensions,
  68.  *  sonata-project/twig-extensions
  69.  * instead.
  70.  */
  71. class SonataCoreBundle extends Bundle
  72. {
  73.     public function build(ContainerBuilder $container)
  74.     {
  75.         $container->addCompilerPass(new StatusRendererCompilerPass());
  76.         $container->addCompilerPass(new AdapterCompilerPass());
  77.         $container->addCompilerPass(new FormFactoryCompilerPass());
  78.         $this->registerFormMapping();
  79.     }
  80.     public function boot()
  81.     {
  82.         // not sur we need this at Runtime ...
  83.         $this->registerFormMapping();
  84.     }
  85.     /**
  86.      * Register form mapping information.
  87.      */
  88.     public function registerFormMapping()
  89.     {
  90.         // symfony
  91.         FormHelper::registerFormTypeMapping([
  92.             'form' => FormType::class,
  93.             'birthday' => BirthdayType::class,
  94.             'checkbox' => CheckboxType::class,
  95.             'choice' => ChoiceType::class,
  96.             'collection' => SymfonyCollectionType::class,
  97.             'country' => CountryType::class,
  98.             'date' => DateType::class,
  99.             'datetime' => DateTimeType::class,
  100.             'email' => EmailType::class,
  101.             'file' => FileType::class,
  102.             'hidden' => HiddenType::class,
  103.             'integer' => IntegerType::class,
  104.             'language' => LanguageType::class,
  105.             'locale' => LocaleType::class,
  106.             'money' => MoneyType::class,
  107.             'number' => NumberType::class,
  108.             'password' => PasswordType::class,
  109.             'percent' => PercentType::class,
  110.             'radio' => RadioType::class,
  111.             'repeated' => RepeatedType::class,
  112.             'search' => SearchType::class,
  113.             'textarea' => TextareaType::class,
  114.             'text' => TextType::class,
  115.             'time' => TimeType::class,
  116.             'timezone' => TimezoneType::class,
  117.             'url' => UrlType::class,
  118.             'button' => ButtonType::class,
  119.             'submit' => SubmitType::class,
  120.             'reset' => ResetType::class,
  121.             'currency' => CurrencyType::class,
  122.             'entity' => EntityType::class,
  123.         ]);
  124.         // core bundle
  125.         FormHelper::registerFormTypeMapping([
  126.             'sonata_type_immutable_array' => ImmutableArrayType::class,
  127.             'sonata_type_boolean' => BooleanType::class,
  128.             'sonata_type_collection' => CollectionType::class,
  129.             'sonata_type_translatable_choice' => TranslatableChoiceType::class,
  130.             'sonata_type_date_range' => DateRangeType::class,
  131.             'sonata_type_datetime_range' => DateTimeRangeType::class,
  132.             'sonata_type_date_picker' => DatePickerType::class,
  133.             'sonata_type_datetime_picker' => DateTimePickerType::class,
  134.             'sonata_type_date_range_picker' => DateRangePickerType::class,
  135.             'sonata_type_datetime_range_picker' => DateTimeRangePickerType::class,
  136.             'sonata_type_equal' => EqualType::class,
  137.             'sonata_type_color' => ColorType::class,
  138.             'sonata_type_color_selector' => ColorSelectorType::class,
  139.         ]);
  140.         $formTypes = [
  141.             'form.type_extension.form.http_foundation',
  142.             'form.type_extension.form.validator',
  143.             'form.type_extension.csrf',
  144.             'form.type_extension.form.data_collector',
  145.         ];
  146.         if (class_exists(DescriptionFormTypeExtension::class)) {
  147.             $formTypes[] = 'nelmio_api_doc.form.extension.description_form_type_extension';
  148.         }
  149.         FormHelper::registerFormExtensionMapping('form'$formTypes);
  150.         FormHelper::registerFormExtensionMapping('repeated', [
  151.             'form.type_extension.repeated.validator',
  152.         ]);
  153.         FormHelper::registerFormExtensionMapping('submit', [
  154.             'form.type_extension.submit.validator',
  155.         ]);
  156.         if ($this->container && $this->container->hasParameter('sonata.core.form.mapping.type')) {
  157.             // from configuration file
  158.             FormHelper::registerFormTypeMapping($this->container->getParameter('sonata.core.form.mapping.type'));
  159.             foreach ($this->container->getParameter('sonata.core.form.mapping.extension') as $ext => $types) {
  160.                 FormHelper::registerFormExtensionMapping($ext$types);
  161.             }
  162.         }
  163.     }
  164. }