Skip to content

Commit

Permalink
Fixed #288, auto generated form types now have unique service name, n…
Browse files Browse the repository at this point in the history
…o possibility for overwritting.
  • Loading branch information
TheCelavi authored and loostro committed May 31, 2016
1 parent fab4312 commit 3998d78
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions DependencyInjection/AdmingeneratorGeneratorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,15 @@ private function registerGeneratedFormsAsServices(ContainerBuilder $container)
private function registerFormsServicesFromGenerator(array $generatorParameters, array $builders, ContainerBuilder $container)
{
$modelParts = explode('\\', $generatorParameters['model']);
$model = array_pop($modelParts);
$model = strtolower(array_pop($modelParts)); // @TODO: BC Support, remove it starting from v.3.0.0
$fullQualifiedNormalizedModelName = strtolower(str_replace('\\', '_', ltrim($generatorParameters['model'])));
$formsBundleNamespace = sprintf(
'%s%s\\Form\\Type\\%s',
$generatorParameters['namespace_prefix'] ? $generatorParameters['namespace_prefix'] . '\\' : '',
$generatorParameters['bundle_name'],
$generatorParameters['prefix']
);

$authorizationCheckerServiceReference = new Reference('security.authorization_checker');

if (in_array('new', $builders)) {
Expand All @@ -284,7 +286,8 @@ private function registerFormsServicesFromGenerator(array $generatorParameters,
->addMethodCall('setAuthorizationChecker', array($authorizationCheckerServiceReference))
->addTag('form.type');

$container->setDefinition('admingen_generator_' . strtolower($model) . '_new', $newDefinition);
$container->setDefinition(($id = 'admingen_generator_' . $fullQualifiedNormalizedModelName . '_new'), $newDefinition);
$container->setAlias('admingen_generator_' . $model . '_new', $id);
}

if (in_array('edit', $builders)) {
Expand All @@ -293,7 +296,8 @@ private function registerFormsServicesFromGenerator(array $generatorParameters,
->addMethodCall('setAuthorizationChecker', array($authorizationCheckerServiceReference))
->addTag('form.type');

$container->setDefinition('admingen_generator_' . strtolower($model) . '_edit', $editDefinition);
$container->setDefinition(($id = 'admingen_generator_' . $fullQualifiedNormalizedModelName . '_edit'), $editDefinition);
$container->setAlias('admingen_generator_' . $model . '_edit', $id);
}

if (in_array('list', $builders) || in_array('nested_list', $builders)) {
Expand All @@ -302,7 +306,8 @@ private function registerFormsServicesFromGenerator(array $generatorParameters,
->addMethodCall('setAuthorizationChecker', array($authorizationCheckerServiceReference))
->addTag('form.type');

$container->setDefinition('admingen_generator_' . strtolower($model) . '_filter', $filterDefinition);
$container->setDefinition(($id = 'admingen_generator_' . $fullQualifiedNormalizedModelName . '_filter'), $filterDefinition);
$container->setAlias('admingen_generator_' . $model . '_filter', $id);
}
}

Expand Down

0 comments on commit 3998d78

Please sign in to comment.