vendor/thecadien/sulu-news-bundle/DependencyInjection/NewsExtension.php line 37

  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of TheCadien/SuluNewsBundle.
  5.  *
  6.  * (c) Oliver Kossin
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace TheCadien\Bundle\SuluNewsBundle\DependencyInjection;
  12. use Sulu\Bundle\PersistenceBundle\DependencyInjection\PersistenceExtensionTrait;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  16. use Symfony\Component\DependencyInjection\Loader;
  17. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  18. use TheCadien\Bundle\SuluNewsBundle\Admin\NewsAdmin;
  19. use TheCadien\Bundle\SuluNewsBundle\Entity\News;
  20. /**
  21.  * This is the class that loads and manages your bundle configuration.
  22.  *
  23.  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
  24.  */
  25. class NewsExtension extends Extension implements PrependExtensionInterface
  26. {
  27.     use PersistenceExtensionTrait;
  28.     /**
  29.      * Allow an extension to prepend the extension configurations.
  30.      */
  31.     public function prepend(ContainerBuilder $container): void
  32.     {
  33.         if ($container->hasExtension('sulu_search')) {
  34.             $container->prependExtensionConfig(
  35.                 'sulu_search',
  36.                 [
  37.                     'indexes' => [
  38.                         'news' => [
  39.                             'name' => 'News',
  40.                             'icon' => 'su-newspaper',
  41.                             'view' => [
  42.                                 'name' => NewsAdmin::NEWS_EDIT_FORM_VIEW,
  43.                                 'result_to_view' => [
  44.                                     'id' => 'id',
  45.                                     'locale' => 'locale',
  46.                                 ],
  47.                             ],
  48.                             'security_context' => NewsAdmin::SECURITY_CONTEXT,
  49.                         ],
  50.                     ],
  51.                 ]
  52.             );
  53.         }
  54.         if ($container->hasExtension('sulu_route')) {
  55.             $container->prependExtensionConfig(
  56.                 'sulu_route',
  57.                 [
  58.                     'mappings' => [
  59.                         News::class => [
  60.                             'generator' => 'schema',
  61.                             'options' => ['route_schema' => '/news/{object.getId()}'],
  62.                             'resource_key' => News::RESOURCE_KEY,
  63.                         ],
  64.                     ],
  65.                 ]
  66.             );
  67.         }
  68.         if ($container->hasExtension('sulu_admin')) {
  69.             $container->prependExtensionConfig(
  70.                 'sulu_admin',
  71.                 [
  72.                     'lists' => [
  73.                         'directories' => [
  74.                             __DIR__.'/../Resources/config/lists',
  75.                         ],
  76.                     ],
  77.                     'forms' => [
  78.                         'directories' => [
  79.                             __DIR__.'/../Resources/config/forms',
  80.                         ],
  81.                     ],
  82.                     'resources' => [
  83.                         'news' => [
  84.                             'routes' => [
  85.                                 'list' => 'app.get_news',
  86.                                 'detail' => 'app.get_news',
  87.                             ],
  88.                         ],
  89.                     ],
  90.                     'field_type_options' => [
  91.                         'selection' => [
  92.                             'news_selection' => [
  93.                                 'default_type' => 'list_overlay',
  94.                                 'resource_key' => News::RESOURCE_KEY,
  95.                                 'view' => [
  96.                                     'name' => 'app.news_edit_form',
  97.                                     'result_to_view' => [
  98.                                         'id' => 'id',
  99.                                     ],
  100.                                 ],
  101.                                 'types' => [
  102.                                     'auto_complete' => [
  103.                                         'display_property' => 'title',
  104.                                         'search_properties' => ['title'],
  105.                                     ],
  106.                                     'list_overlay' => [
  107.                                         'adapter' => 'table',
  108.                                         'list_key' => 'news',
  109.                                         'display_properties' => ['title'],
  110.                                         'label' => 'sulu_news.news_select',
  111.                                         'icon' => 'su-newspaper',
  112.                                         'overlay_title' => 'sulu_news.single_news_selection_overlay_title',
  113.                                     ],
  114.                                 ],
  115.                             ],
  116.                         ],
  117.                     ],
  118.                 ]
  119.             );
  120.         }
  121.         $container->prependExtensionConfig(
  122.             'sulu_news',
  123.             ['templates' => ['view' => 'news/index.html.twig']]
  124.         );
  125.         $container->loadFromExtension('framework', [
  126.             'default_locale' => 'en',
  127.             'translator' => ['paths' => [__DIR__.'/../Resources/config/translations/']],
  128.             // ...
  129.         ]);
  130.     }
  131.     /**
  132.      * {@inheritdoc}
  133.      */
  134.     public function load(array $configsContainerBuilder $container): void
  135.     {
  136.         $configuration = new Configuration();
  137.         $config $this->processConfiguration($configuration$configs);
  138.         $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  139.         $loader->load('services.xml');
  140.         $loader->load('controller.xml');
  141.         $this->configurePersistence($config['objects'], $container);
  142.     }
  143. }