vendor/sonata-project/admin-bundle/src/SonataAdminBundle.php line 47

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\AdminBundle;
  12. use Mopa\Bundle\BootstrapBundle\Form\Type\TabType;
  13. use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass;
  14. use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass;
  15. use Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass;
  16. use Sonata\AdminBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
  17. use Sonata\AdminBundle\DependencyInjection\Compiler\ModelManagerCompilerPass;
  18. use Sonata\AdminBundle\DependencyInjection\Compiler\ObjectAclManipulatorCompilerPass;
  19. use Sonata\AdminBundle\DependencyInjection\Compiler\TwigStringExtensionCompilerPass;
  20. use Sonata\AdminBundle\Form\Type\AdminType;
  21. use Sonata\AdminBundle\Form\Type\ChoiceFieldMaskType;
  22. use Sonata\AdminBundle\Form\Type\CollectionType;
  23. use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
  24. use Sonata\AdminBundle\Form\Type\Filter\DateRangeType;
  25. use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType;
  26. use Sonata\AdminBundle\Form\Type\Filter\DateTimeType;
  27. use Sonata\AdminBundle\Form\Type\Filter\DateType;
  28. use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
  29. use Sonata\AdminBundle\Form\Type\Filter\NumberType;
  30. use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
  31. use Sonata\AdminBundle\Form\Type\ModelHiddenType;
  32. use Sonata\AdminBundle\Form\Type\ModelListType;
  33. use Sonata\AdminBundle\Form\Type\ModelReferenceType;
  34. use Sonata\AdminBundle\Form\Type\ModelType;
  35. use Sonata\CoreBundle\Form\FormHelper;
  36. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  37. use Symfony\Component\DependencyInjection\ContainerBuilder;
  38. use Symfony\Component\HttpKernel\Bundle\Bundle;
  39. /**
  40.  * @final since sonata-project/admin-bundle 3.52
  41.  */
  42. class SonataAdminBundle extends Bundle
  43. {
  44.     public function build(ContainerBuilder $container)
  45.     {
  46.         $container->addCompilerPass(new AddDependencyCallsCompilerPass());
  47.         $container->addCompilerPass(new AddFilterTypeCompilerPass());
  48.         $container->addCompilerPass(new ExtensionCompilerPass());
  49.         $container->addCompilerPass(new GlobalVariablesCompilerPass());
  50.         $container->addCompilerPass(new ModelManagerCompilerPass());
  51.         $container->addCompilerPass(new ObjectAclManipulatorCompilerPass());
  52.         $container->addCompilerPass(new TwigStringExtensionCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1);
  53.         $this->registerFormMapping();
  54.     }
  55.     public function boot()
  56.     {
  57.         $this->registerFormMapping();
  58.     }
  59.     /**
  60.      * Register form mapping information.
  61.      *
  62.      * NEXT_MAJOR: remove this method
  63.      */
  64.     public function registerFormMapping()
  65.     {
  66.         if (!class_exists(FormHelper::class)) {
  67.             return;
  68.         }
  69.         $formMapping = [
  70.             'sonata_type_admin' => AdminType::class,
  71.             'sonata_type_model' => ModelType::class,
  72.             'sonata_type_model_list' => ModelListType::class,
  73.             'sonata_type_model_reference' => ModelReferenceType::class,
  74.             'sonata_type_model_hidden' => ModelHiddenType::class,
  75.             'sonata_type_model_autocomplete' => ModelAutocompleteType::class,
  76.             'sonata_type_native_collection' => CollectionType::class,
  77.             'sonata_type_choice_field_mask' => ChoiceFieldMaskType::class,
  78.             'sonata_type_filter_number' => NumberType::class,
  79.             'sonata_type_filter_choice' => ChoiceType::class,
  80.             'sonata_type_filter_default' => DefaultType::class,
  81.             'sonata_type_filter_date' => DateType::class,
  82.             'sonata_type_filter_date_range' => DateRangeType::class,
  83.             'sonata_type_filter_datetime' => DateTimeType::class,
  84.             'sonata_type_filter_datetime_range' => DateTimeRangeType::class,
  85.         ];
  86.         if (class_exists(TabType::class)) {
  87.             $formMapping['tab'] = TabType::class;
  88.         }
  89.         FormHelper::registerFormTypeMapping($formMapping);
  90.         FormHelper::registerFormExtensionMapping('form', [
  91.             'sonata.admin.form.extension.field',
  92.             'mopa_bootstrap.form.type_extension.help',
  93.             'mopa_bootstrap.form.type_extension.legend',
  94.             'mopa_bootstrap.form.type_extension.error',
  95.             'mopa_bootstrap.form.type_extension.widget',
  96.             'mopa_bootstrap.form.type_extension.horizontal',
  97.             'mopa_bootstrap.form.type_extension.widget_collection',
  98.             'mopa_bootstrap.form.type_extension.tabbed',
  99.         ]);
  100.         FormHelper::registerFormExtensionMapping('choice', [
  101.             'sonata.admin.form.extension.choice',
  102.         ]);
  103.         FormHelper::registerFormExtensionMapping('button', [
  104.             'mopa_bootstrap.form.type_extension.button',
  105.         ]);
  106.         FormHelper::registerFormExtensionMapping('date', [
  107.             'mopa_bootstrap.form.type_extension.date',
  108.         ]);
  109.     }
  110. }