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

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. class SonataCoreBundle extends Bundle
  64. {
  65.     public function build(ContainerBuilder $container)
  66.     {
  67.         $container->addCompilerPass(new StatusRendererCompilerPass());
  68.         $container->addCompilerPass(new AdapterCompilerPass());
  69.         $container->addCompilerPass(new FormFactoryCompilerPass());
  70.         $this->registerFormMapping();
  71.     }
  72.     public function boot()
  73.     {
  74.         // not sur we need this at Runtime ...
  75.         $this->registerFormMapping();
  76.     }
  77.     /**
  78.      * Register form mapping information.
  79.      */
  80.     public function registerFormMapping()
  81.     {
  82.         // symfony
  83.         FormHelper::registerFormTypeMapping([
  84.             'form' => FormType::class,
  85.             'birthday' => BirthdayType::class,
  86.             'checkbox' => CheckboxType::class,
  87.             'choice' => ChoiceType::class,
  88.             'collection' => SymfonyCollectionType::class,
  89.             'country' => CountryType::class,
  90.             'date' => DateType::class,
  91.             'datetime' => DateTimeType::class,
  92.             'email' => EmailType::class,
  93.             'file' => FileType::class,
  94.             'hidden' => HiddenType::class,
  95.             'integer' => IntegerType::class,
  96.             'language' => LanguageType::class,
  97.             'locale' => LocaleType::class,
  98.             'money' => MoneyType::class,
  99.             'number' => NumberType::class,
  100.             'password' => PasswordType::class,
  101.             'percent' => PercentType::class,
  102.             'radio' => RadioType::class,
  103.             'repeated' => RepeatedType::class,
  104.             'search' => SearchType::class,
  105.             'textarea' => TextareaType::class,
  106.             'text' => TextType::class,
  107.             'time' => TimeType::class,
  108.             'timezone' => TimezoneType::class,
  109.             'url' => UrlType::class,
  110.             'button' => ButtonType::class,
  111.             'submit' => SubmitType::class,
  112.             'reset' => ResetType::class,
  113.             'currency' => CurrencyType::class,
  114.             'entity' => EntityType::class,
  115.         ]);
  116.         // core bundle
  117.         FormHelper::registerFormTypeMapping([
  118.             'sonata_type_immutable_array' => ImmutableArrayType::class,
  119.             'sonata_type_boolean' => BooleanType::class,
  120.             'sonata_type_collection' => CollectionType::class,
  121.             'sonata_type_translatable_choice' => TranslatableChoiceType::class,
  122.             'sonata_type_date_range' => DateRangeType::class,
  123.             'sonata_type_datetime_range' => DateTimeRangeType::class,
  124.             'sonata_type_date_picker' => DatePickerType::class,
  125.             'sonata_type_datetime_picker' => DateTimePickerType::class,
  126.             'sonata_type_date_range_picker' => DateRangePickerType::class,
  127.             'sonata_type_datetime_range_picker' => DateTimeRangePickerType::class,
  128.             'sonata_type_equal' => EqualType::class,
  129.             'sonata_type_color' => ColorType::class,
  130.             'sonata_type_color_selector' => ColorSelectorType::class,
  131.         ]);
  132.         $formTypes = [
  133.             'form.type_extension.form.http_foundation',
  134.             'form.type_extension.form.validator',
  135.             'form.type_extension.csrf',
  136.             'form.type_extension.form.data_collector',
  137.         ];
  138.         if (class_exists(DescriptionFormTypeExtension::class)) {
  139.             $formTypes[] = 'nelmio_api_doc.form.extension.description_form_type_extension';
  140.         }
  141.         FormHelper::registerFormExtensionMapping('form'$formTypes);
  142.         FormHelper::registerFormExtensionMapping('repeated', [
  143.             'form.type_extension.repeated.validator',
  144.         ]);
  145.         FormHelper::registerFormExtensionMapping('submit', [
  146.             'form.type_extension.submit.validator',
  147.         ]);
  148.         if ($this->container && $this->container->hasParameter('sonata.core.form.mapping.type')) {
  149.             // from configuration file
  150.             FormHelper::registerFormTypeMapping($this->container->getParameter('sonata.core.form.mapping.type'));
  151.             foreach ($this->container->getParameter('sonata.core.form.mapping.extension') as $ext => $types) {
  152.                 FormHelper::registerFormExtensionMapping($ext$types);
  153.             }
  154.         }
  155.     }
  156. }