vendor/sulu/form-bundle/DependencyInjection/SuluFormExtension.php line 196

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\FormBundle\DependencyInjection;
  11. use Sulu\Bundle\FormBundle\Controller\FormTokenController;
  12. use Sulu\Bundle\FormBundle\Controller\FormWebsiteController;
  13. use Sulu\Bundle\FormBundle\Entity\Form;
  14. use Sulu\Component\HttpKernel\SuluKernel;
  15. use Symfony\Component\Config\FileLocator;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  18. use Symfony\Component\DependencyInjection\Loader;
  19. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  20. use Symfony\Component\Mailer\MailerInterface;
  21. /**
  22.  * This is the class that loads and manages your bundle configuration.
  23.  *
  24.  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
  25.  *
  26.  * @internal
  27.  */
  28. class SuluFormExtension extends Extension implements PrependExtensionInterface
  29. {
  30.     public const SYSTEM_COLLECTION_ROOT 'sulu_form';
  31.     public const MEDIA_COLLECTION_STRATEGY_SINGLE 'single';
  32.     public const MEDIA_COLLECTION_STRATEGY_TREE 'tree';
  33.     public function prepend(ContainerBuilder $container): void
  34.     {
  35.         if ($container->hasExtension('fos_js_routing')) {
  36.             $container->prependExtensionConfig(
  37.                 'fos_js_routing',
  38.                 [
  39.                     'routes_to_expose' => [
  40.                         'sulu_form.get_forms',
  41.                         'sulu_form.get_form',
  42.                         'sulu_form.get_dynamics',
  43.                         'sulu_form.delete_dynamic',
  44.                     ],
  45.                 ]
  46.             );
  47.         }
  48.         if ($container->hasExtension('framework')) {
  49.             $container->prependExtensionConfig(
  50.                 'framework',
  51.                 [
  52.                     'esi' => [
  53.                         'enabled' => true,
  54.                     ],
  55.                 ]
  56.             );
  57.         }
  58.         if ($container->hasExtension('sulu_media')) {
  59.             $container->prependExtensionConfig(
  60.                 'sulu_media',
  61.                 [
  62.                     'system_collections' => [
  63.                         self::SYSTEM_COLLECTION_ROOT => [
  64.                             'meta_title' => ['en' => 'Sulu forms''de' => 'Sulu Formulare'],
  65.                             'collections' => [
  66.                                 'attachments' => [
  67.                                     'meta_title' => ['en' => 'Attachments''de' => 'Anhänge'],
  68.                                 ],
  69.                             ],
  70.                         ],
  71.                     ],
  72.                 ]
  73.             );
  74.         }
  75.         if ($container->hasExtension('sulu_admin')) {
  76.             $container->prependExtensionConfig(
  77.                 'sulu_admin',
  78.                 [
  79.                     'lists' => [
  80.                         'directories' => [
  81.                             __DIR__ '/../Resources/config/lists',
  82.                         ],
  83.                     ],
  84.                     'resources' => [
  85.                         Form::RESOURCE_KEY => [
  86.                             'routes' => [
  87.                                 'list' => 'sulu_form.get_forms',
  88.                                 'detail' => 'sulu_form.get_form',
  89.                             ],
  90.                         ],
  91.                         'dynamic_forms' => [
  92.                             'routes' => [
  93.                                 'list' => 'sulu_form.get_dynamics',
  94.                                 'detail' => 'sulu_form.delete_dynamic',
  95.                             ],
  96.                         ],
  97.                     ],
  98.                     'field_type_options' => [
  99.                         'single_selection' => [
  100.                             'single_form_selection' => [
  101.                                 'default_type' => 'list_overlay',
  102.                                 'resource_key' => Form::RESOURCE_KEY,
  103.                                 'types' => [
  104.                                     'list_overlay' => [
  105.                                         'adapter' => 'table',
  106.                                         'list_key' => 'forms',
  107.                                         'display_properties' => ['title'],
  108.                                         'empty_text' => 'sulu_form.single_form_selection.no_form_selected',
  109.                                         'icon' => 'su-th-list',
  110.                                         'overlay_title' => 'sulu_form.single_form_selection.overlay_title',
  111.                                     ],
  112.                                 ],
  113.                             ],
  114.                         ],
  115.                     ],
  116.                 ]
  117.             );
  118.         }
  119.     }
  120.     public function load(array $configsContainerBuilder $container): void
  121.     {
  122.         $configuration = new Configuration();
  123.         $config $this->processConfiguration($configuration$configs);
  124.         $mediaCollectionStrategy $config['media_collection_strategy'] ? $config['media_collection_strategy'] : $config['media']['collection_strategy'];
  125.         $container->setParameter('sulu_form.csrf_protection'$config['csrf_protection']);
  126.         $container->setParameter('sulu_form.mail.from'$config['mail']['from']);
  127.         $container->setParameter('sulu_form.mail.to'$config['mail']['to']);
  128.         $container->setParameter('sulu_form.mail.sender'$config['mail']['sender']);
  129.         $container->setParameter('sulu_form.mail.template.notify'$config['mail']['templates']['notify']);
  130.         $container->setParameter('sulu_form.mail.template.notify_plain_text'$config['mail']['templates']['notify_plain_text']);
  131.         $container->setParameter('sulu_form.mail.template.customer'$config['mail']['templates']['customer']);
  132.         $container->setParameter('sulu_form.mail.template.customer_plain_text'$config['mail']['templates']['customer_plain_text']);
  133.         $container->setParameter('sulu_form.ajax_templates'$config['ajax_templates']);
  134.         $container->setParameter('sulu_form.dynamic_widths'$config['dynamic_widths']);
  135.         $container->setParameter('sulu_form.dynamic_auto_title'$config['dynamic_auto_title']);
  136.         $container->setParameter('sulu_form.sendinblue_api_key'$config['sendinblue_api_key']);
  137.         $container->setParameter('sulu_form.mailchimp_api_key'$config['mailchimp_api_key']);
  138.         $container->setParameter('sulu_form.mailchimp_subscribe_status'$config['mailchimp_subscribe_status']);
  139.         $container->setParameter('sulu_form.dynamic_lists.config'$config['dynamic_lists']);
  140.         $container->setParameter('sulu_form.media_collection_strategy'$mediaCollectionStrategy);
  141.         $container->setParameter('sulu_form.static_forms'$config['static_forms']);
  142.         $container->setParameter('sulu_form.dynamic_disabled_types'$config['dynamic_disabled_types']);
  143.         // Default Media Collection Strategy
  144.         $container->setAlias(
  145.             'sulu_form.media_collection_strategy.default',
  146.             'sulu_form.media_collection_strategy.' $mediaCollectionStrategy
  147.         );
  148.         // Dynamic List Builder
  149.         $container->setParameter(
  150.             'sulu_form.dynamic_list_builder.default',
  151.             $config['dynamic_list_builder']['default']
  152.         );
  153.         $container->setParameter(
  154.             'sulu_form.dynamic_list_builder.delimiter',
  155.             $config['dynamic_list_builder']['delimiter']
  156.         );
  157.         $container->setParameter(
  158.             'sulu_form.honeypot_field',
  159.             $config['honeypot']['field']
  160.         );
  161.         $container->setParameter(
  162.             'sulu_form.honeypot_strategy',
  163.             $config['honeypot']['strategy']
  164.         );
  165.         // Load services
  166.         $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  167.         $loader->load('services.xml');
  168.         $loader->load('types.xml');
  169.         $loader->load('title-providers.xml');
  170.         $definition $container->getDefinition('sulu_mail.null_helper');
  171.         $reflection = new \ReflectionClass($definition);
  172.         $reflectionMethod $reflection->getMethod('setDeprecated');
  173.         if (isset($reflectionMethod->getParameters()[1]) && 'version' === $reflectionMethod->getParameters()[1]->getName()) {
  174.             $definition->setDeprecated('sulu/form-bundle''2.3''The "%service_id%" is deprecated use the mailer configuration instead.');
  175.         } else {
  176.             $definition->setDeprecated(true'The "%service_id%" is deprecated use the mailer configuration instead.');
  177.         }
  178.         if ($config['sendinblue_api_key']) {
  179.             if (!\class_exists(\SendinBlue\Client\Configuration::class)) {
  180.                 throw new \LogicException('You need to install the "sendinblue/api-v3-sdk" package to use the sendinblue type.');
  181.             }
  182.             $loader->load('type_sendinblue.xml');
  183.         }
  184.         if ($config['mailchimp_api_key']) {
  185.             if (!\class_exists(\DrewM\MailChimp\MailChimp::class)) {
  186.                 throw new \LogicException('You need to install the "drewm/mailchimp-api" package to use the mailchimp type.');
  187.             }
  188.             $loader->load('type_mailchimp.xml');
  189.         }
  190.         /** @var array<string, class-string> $bundles */
  191.         $bundles $container->getParameter('kernel.bundles');
  192.         if (\array_key_exists('SuluArticleBundle'$bundles)) {
  193.             $loader->load('article.xml');
  194.         }
  195.         if (\array_key_exists('SuluTrashBundle'$bundles)) {
  196.             $loader->load('services_trash.xml');
  197.         }
  198.         if (\class_exists(\EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType::class)) {
  199.             $loader->load('type_recaptcha.xml');
  200.         }
  201.         if (SuluKernel::CONTEXT_WEBSITE === $container->getParameter('sulu.context')) {
  202.             $container->setAlias(FormWebsiteController::class, 'sulu_form.form_website_controller')
  203.                 ->setPublic(true);
  204.             $container->setAlias(FormTokenController::class, 'sulu_form.form_token_controller')
  205.                 ->setPublic(true);
  206.         }
  207.         $container->setParameter('sulu_mail.mail.helper_name'$config['mail']['helper']);
  208.         if ($config['media']['protected']) {
  209.             $loader->load('protected_media.xml');
  210.         }
  211.         $this->configureHelper($loader$config$container);
  212.     }
  213.     /**
  214.      * @param mixed[] $config
  215.      */
  216.     private function configureHelper(Loader\XmlFileLoader $loader, array $configContainerBuilder $container): void
  217.     {
  218.         $helper $config['mail']['helper'];
  219.         if (\method_exists($container'resolveEnvPlaceholders')) {
  220.             $helper $container->resolveEnvPlaceholders($helpertrue);
  221.         }
  222.         if (\class_exists(\Swift_Mailer::class)) {
  223.             $helper $helper ?: 'swift_mailer';
  224.             $loader->load('swift_mailer.xml');
  225.         }
  226.         if (\interface_exists(MailerInterface::class)) {
  227.             $helper $helper ?: 'mailer';
  228.             $loader->load('mailer.xml');
  229.         }
  230.         if (!$helper) {
  231.             throw new \LogicException('The SuluFormBundle requires "swiftmailer/swiftmailer" or "symfony/mailer" to be installed.');
  232.         }
  233.         $container->setAlias('sulu.mail.helper''sulu.mail.' $helper);
  234.     }
  235. }