mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add support for re-use of same controller in CRUD
This commit is contained in:
parent
6109520c95
commit
ce365b2c41
@ -62,10 +62,9 @@ class CRUDRoutesLoader
|
|||||||
protected function loadConfig($config): RouteCollection
|
protected function loadConfig($config): RouteCollection
|
||||||
{
|
{
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
|
|
||||||
foreach ($config['actions'] as $name => $action) {
|
foreach ($config['actions'] as $name => $action) {
|
||||||
$defaults = [
|
$defaults = [
|
||||||
'_controller' => $action['controller'] ?? $config['controller'].'::'.$name
|
'_controller' => 'cscrud_'.$config['name'].'_controller'.':'.($action['controller_action'] ?? $name)
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($name === 'index') {
|
if ($name === 'index') {
|
||||||
|
@ -228,6 +228,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
|
|
||||||
foreach ($config as $crudEntry) {
|
foreach ($config as $crudEntry) {
|
||||||
$controller = $crudEntry['controller'];
|
$controller = $crudEntry['controller'];
|
||||||
|
$controllerServiceName = 'cscrud_'.$crudEntry['name'].'_controller';
|
||||||
$name = $crudEntry['name'];
|
$name = $crudEntry['name'];
|
||||||
|
|
||||||
// check for existing crud names
|
// check for existing crud names
|
||||||
@ -235,15 +236,16 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
throw new LogicException(sprintf("the name %s is defined twice in CRUD", $name));
|
throw new LogicException(sprintf("the name %s is defined twice in CRUD", $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$container->has($controller)) {
|
if (!$container->has($controllerServiceName)) {
|
||||||
$controllerDefinition = new Definition($controller);
|
$controllerDefinition = new Definition($controller);
|
||||||
$controllerDefinition->addTag('controller.service_arguments');
|
$controllerDefinition->addTag('controller.service_arguments');
|
||||||
$controllerDefinition->setAutoconfigured(true);
|
$controllerDefinition->setAutoconfigured(true);
|
||||||
$container->setDefinition($controller, $controllerDefinition);
|
$controllerDefinition->setClass($crudEntry['controller']);
|
||||||
|
$container->setDefinition($controllerServiceName, $controllerDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
$container->setParameter('chill_main_crud_config_'.$name, $crudEntry);
|
$container->setParameter('chill_main_crud_config_'.$name, $crudEntry);
|
||||||
$container->getDefinition($controller)
|
$container->getDefinition($controllerServiceName)
|
||||||
->addMethodCall('setCrudConfig', ['%chill_main_crud_config_'.$name.'%']);
|
->addMethodCall('setCrudConfig', ['%chill_main_crud_config_'.$name.'%']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,10 +134,10 @@ class Configuration implements ConfigurationInterface
|
|||||||
->useAttributeAsKey('name')
|
->useAttributeAsKey('name')
|
||||||
->arrayPrototype()
|
->arrayPrototype()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('controller')
|
->scalarNode('controller_action')
|
||||||
->defaultNull()
|
->defaultNull()
|
||||||
->info('the method name to call in the route. Will be set to the action name if left empty.')
|
->info('the method name to call in the route. Will be set to the action name if left empty.')
|
||||||
->example("'MyBundle\Controller\MyCrudController::action'")
|
->example("'action'")
|
||||||
->end()
|
->end()
|
||||||
->scalarNode('path')
|
->scalarNode('path')
|
||||||
->defaultNull()
|
->defaultNull()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user