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.         $bundles $container->getParameter('kernel.bundles');
  191.         if (\array_key_exists('SuluArticleBundle'$bundles)) {
  192.             $loader->load('article.xml');
  193.         }
  194.         if (\array_key_exists('SuluTrashBundle'$bundles)) {
  195.             $loader->load('services_trash.xml');
  196.         }
  197.         if (\class_exists(\EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType::class)) {
  198.             $loader->load('type_recaptcha.xml');
  199.         }
  200.         if (SuluKernel::CONTEXT_WEBSITE === $container->getParameter('sulu.context')) {
  201.             $container->setAlias(FormWebsiteController::class, 'sulu_form.form_website_controller')
  202.                 ->setPublic(true);
  203.             $container->setAlias(FormTokenController::class, 'sulu_form.form_token_controller')
  204.                 ->setPublic(true);
  205.         }
  206.         $container->setParameter('sulu_mail.mail.helper_name'$config['mail']['helper']);
  207.         if ($config['media']['protected']) {
  208.             $loader->load('protected_media.xml');
  209.         }
  210.         $this->configureHelper($loader$config$container);
  211.     }
  212.     /**
  213.      * @param mixed[] $config
  214.      */
  215.     private function configureHelper(Loader\XmlFileLoader $loader, array $configContainerBuilder $container): void
  216.     {
  217.         $helper $config['mail']['helper'];
  218.         if (\method_exists($container'resolveEnvPlaceholders')) {
  219.             $helper $container->resolveEnvPlaceholders($helpertrue);
  220.         }
  221.         if (\class_exists(\Swift_Mailer::class)) {
  222.             $helper $helper ?: 'swift_mailer';
  223.             $loader->load('swift_mailer.xml');
  224.         }
  225.         if (\interface_exists(MailerInterface::class)) {
  226.             $helper $helper ?: 'mailer';
  227.             $loader->load('mailer.xml');
  228.         }
  229.         if (!$helper) {
  230.             throw new \LogicException('The SuluFormBundle requires "swiftmailer/swiftmailer" or "symfony/mailer" to be installed.');
  231.         }
  232.         $container->setAlias('sulu.mail.helper''sulu.mail.' $helper);
  233.     }
  234. }