<?php
namespace Eckinox\AdminUiBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class EckinoxAdminUiExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container)
{
$configs = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../../config')
);
$loader->load('services.yaml');
if (isset($configs['menus'])) {
foreach ($configs['menus'] as $type => $menus) {
if ( $type == 'mega' ) {
$configs['menus'][$type] = $this->applyPriorities($menus);
} else {
foreach ($menus as $name => $children) {
$configs['menus'][$type][$name] = $this->applyPriorities($children);
}
}
}
}
$container->setParameter('eckinox_admin_ui.menus', $configs['menus'] ?? []);
$container->setParameter('eckinox_admin_ui.dropzones', $configs['dropzones'] ?? []);
$container->setParameter('eckinox_admin_ui.datatables', $configs['datatables'] ?? []);
$container->setParameter('eckinox_admin_ui.assets', $configs['assets'] ?? []);
}
public function prepend(ContainerBuilder $container)
{
$container->prependExtensionConfig('twig', [
'form_themes' => ['@EckinoxAdminUi/form/theme.html.twig']
]);
$container->prependExtensionConfig('framework', [
'assets' => ['version_strategy' => 'incenteev_hashed_asset.strategy']
]);
// Set default setting
$container->prependExtensionConfig('eckinox_admin_ui', [
'dropzones' => [
'_default' => [
'accept_file_types' => 'image/gif,image/jpg,image/png,application/pdf,application/x-pdf',
'auto_start' => true ,
'thumbnail_width' => 80,
'thumbnail_height' => 80,
'parallel_uploads' => 20,
'show_thumbnail' => true,
'max_files' => 100,
'max_size' => 10
]
]
]);
}
public function applyPriorities(array $children) {
foreach($children as $name => $child) {
if(isset($child['children']) && $child['children']) {
$children[$name]['children'] = $this->applyPriorities($child['children']);
}
if(isset($child['sections']) && $child['sections']) {
$children[$name]['sections'] = $this->applyPriorities($child['sections']);
}
}
uasort($children, function($a, $b) {
return $a['priority'] < $b['priority'];
});
return $children;
}
}