vendor/eckinox/admin-ui-bundle/src/DependencyInjection/EckinoxAdminUiExtension.php line 68

Open in your IDE?
  1. <?php
  2. namespace Eckinox\AdminUiBundle\DependencyInjection;
  3. use Symfony\Component\DependencyInjection\ContainerBuilder;
  4. use Symfony\Component\DependencyInjection\Extension\Extension;
  5. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  6. use Symfony\Component\Config\FileLocator;
  7. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  8. class EckinoxAdminUiExtension extends Extension implements PrependExtensionInterface
  9. {
  10.     public function load(array $configsContainerBuilder $container)
  11.     {
  12.         $configs $this->processConfiguration($this->getConfiguration([], $container), $configs);
  13.         $loader = new YamlFileLoader(
  14.             $container,
  15.             new FileLocator(__DIR__.'/../../config')
  16.         );
  17.         $loader->load('services.yaml');
  18.         if (isset($configs['menus'])) {
  19.             foreach ($configs['menus'] as $type => $menus) {
  20.                 if ( $type == 'mega' ) {
  21.                     $configs['menus'][$type] = $this->applyPriorities($menus);
  22.                 } else {
  23.                     foreach ($menus as $name => $children) {
  24.                         $configs['menus'][$type][$name] = $this->applyPriorities($children);
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.         $container->setParameter('eckinox_admin_ui.menus'$configs['menus'] ?? []);
  30.         $container->setParameter('eckinox_admin_ui.dropzones'$configs['dropzones'] ?? []);
  31.         $container->setParameter('eckinox_admin_ui.datatables'$configs['datatables'] ?? []);
  32.         $container->setParameter('eckinox_admin_ui.assets'$configs['assets'] ?? []);
  33.     }
  34.     public function prepend(ContainerBuilder $container)
  35.     {
  36.         $container->prependExtensionConfig('twig', [
  37.             'form_themes' => ['@EckinoxAdminUi/form/theme.html.twig']
  38.         ]);
  39.         $container->prependExtensionConfig('framework', [
  40.             'assets' => ['version_strategy' => 'incenteev_hashed_asset.strategy']
  41.         ]);
  42.         // Set default setting
  43.         $container->prependExtensionConfig('eckinox_admin_ui', [
  44.             'dropzones' => [
  45.                 '_default' => [
  46.                     'accept_file_types' => 'image/gif,image/jpg,image/png,application/pdf,application/x-pdf',
  47.                     'auto_start' => true ,
  48.                     'thumbnail_width' => 80,
  49.                     'thumbnail_height' => 80,
  50.                     'parallel_uploads' => 20,
  51.                     'show_thumbnail' => true,
  52.                     'max_files' => 100,
  53.                     'max_size' => 10
  54.                 ]
  55.             ]
  56.         ]);
  57.     }
  58.     public function applyPriorities(array $children) {
  59.         foreach($children as $name => $child) {
  60.             if(isset($child['children']) && $child['children']) {
  61.                 $children[$name]['children'] = $this->applyPriorities($child['children']);
  62.             }
  63.             if(isset($child['sections']) && $child['sections']) {
  64.                 $children[$name]['sections'] = $this->applyPriorities($child['sections']);
  65.             }
  66.         }
  67.         uasort($children, function($a$b) {
  68.             return $a['priority'] < $b['priority'];
  69.         });
  70.         return $children;
  71.     }
  72. }