mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'fix/api-crud-improve-loading-for-existing-controller' into 'master'
Fix/api crud improve loading for existing controller See merge request Chill-Projet/chill-bundles!92
This commit is contained in:
commit
ca9ae3874c
@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Chill\MainBundle\Routing\MenuComposer;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -49,29 +50,32 @@ class CRUDControllerCompilerPass implements CompilerPassInterface
|
||||
private function configureCrudController(ContainerBuilder $container, array $crudEntry, string $apiOrCrud): void
|
||||
{
|
||||
$controllerClass = $crudEntry['controller'];
|
||||
|
||||
$controllerServiceName = 'cs'.$apiOrCrud.'_'.$crudEntry['name'].'_controller';
|
||||
|
||||
if ($container->hasDefinition($controllerClass)) {
|
||||
$controller = $container->getDefinition($controllerClass);
|
||||
$container->removeDefinition($controllerClass);
|
||||
$alreadyDefined = true;
|
||||
} else {
|
||||
$controller = new Definition($controllerClass);
|
||||
$alreadyDefined = false;
|
||||
}
|
||||
|
||||
$controller->addTag('controller.service_arguments');
|
||||
if (FALSE === $alreadyDefined) {
|
||||
$controller->setAutoconfigured(true);
|
||||
$controller->setPublic(true);
|
||||
}
|
||||
|
||||
// create config parameter in container
|
||||
$param = 'chill_main_'.$apiOrCrud.'_config_'.$crudEntry['name'];
|
||||
$container->setParameter($param, $crudEntry);
|
||||
$controller->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
||||
|
||||
$container->setDefinition($controllerServiceName, $controller);
|
||||
if ($container->hasDefinition($controllerClass)) {
|
||||
// create an alias to not to re-create the service
|
||||
$alias = new Alias($controllerClass, true);
|
||||
$container->setAlias($controllerServiceName, $alias);
|
||||
|
||||
// add the "addMethodCall"
|
||||
$container->getDefinition($controllerClass)
|
||||
->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
||||
|
||||
} else {
|
||||
$controller = new Definition($controllerClass);
|
||||
|
||||
$controller->addTag('controller.service_arguments');
|
||||
$controller->setAutoconfigured(true);
|
||||
$controller->setPublic(true);
|
||||
|
||||
$controller->addMethodCall('setCrudConfig', ['%'.$param.'%']);
|
||||
|
||||
$container->setDefinition($controllerServiceName, $controller);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class CRUDRoutesLoader extends Loader
|
||||
protected function loadApi(array $crudConfig): RouteCollection
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$controller ='csapi_'.$crudConfig['name'].'_controller';
|
||||
$controller = 'csapi_'.$crudConfig['name'].'_controller';
|
||||
|
||||
foreach ($crudConfig['actions'] as $name => $action) {
|
||||
// filter only on single actions
|
||||
|
Loading…
x
Reference in New Issue
Block a user