|
@@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use Symfony\Component\DependencyInjection\Definition;
|
|
use Symfony\Component\DependencyInjection\Definition;
|
|
|
|
+use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -50,21 +51,20 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $tags) {
|
|
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $tags) {
|
|
foreach ($tags as $attributes) {
|
|
foreach ($tags as $attributes) {
|
|
$definition = $container->getDefinition($id);
|
|
$definition = $container->getDefinition($id);
|
|
-
|
|
|
|
- $arguments = $definition->getArguments();
|
|
|
|
-
|
|
|
|
- if (strlen($arguments[0]) == 0) {
|
|
|
|
- $definition->replaceArgument(0, $id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (strlen($arguments[2]) == 0) {
|
|
|
|
- $definition->replaceArgument(2, 'SonataAdminBundle:CRUD');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ $parentDefinition = $definition instanceof DefinitionDecorator ?
|
|
|
|
+ $container->getDefinition($definition->getParent()) :
|
|
|
|
+ null;
|
|
|
|
+
|
|
|
|
+ $this->replaceDefaultArguments(array(
|
|
|
|
+ 0 => $id,
|
|
|
|
+ 2 => 'SonataAdminBundle:CRUD',
|
|
|
|
+ ), $definition, $parentDefinition);
|
|
$this->applyConfigurationFromAttribute($definition, $attributes);
|
|
$this->applyConfigurationFromAttribute($definition, $attributes);
|
|
$this->applyDefaults($container, $id, $attributes);
|
|
$this->applyDefaults($container, $id, $attributes);
|
|
|
|
|
|
- $arguments = $definition->getArguments();
|
|
|
|
|
|
+ $arguments = $parentDefinition ?
|
|
|
|
+ array_merge($parentDefinition->getArguments(), $definition->getArguments()) :
|
|
|
|
+ $definition->getArguments();
|
|
|
|
|
|
$admins[] = $id;
|
|
$admins[] = $id;
|
|
|
|
|
|
@@ -408,4 +408,27 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
|
|
|
|
$definition->addMethodCall('setTemplates', array($definedTemplates));
|
|
$definition->addMethodCall('setTemplates', array($definedTemplates));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Replace the empty arguments required by the Admin service definition.
|
|
|
|
+ *
|
|
|
|
+ * @param array $defaultArguments
|
|
|
|
+ * @param Definition $definition
|
|
|
|
+ * @param Definition|null $parentDefinition
|
|
|
|
+ */
|
|
|
|
+ private function replaceDefaultArguments(array $defaultArguments, Definition $definition, Definition $parentDefinition = null)
|
|
|
|
+ {
|
|
|
|
+ $arguments = $definition->getArguments();
|
|
|
|
+ $parentArguments = $parentDefinition ? $parentDefinition->getArguments() : array();
|
|
|
|
+
|
|
|
|
+ foreach ($defaultArguments as $index => $value) {
|
|
|
|
+ $declaredInParent = $parentDefinition && array_key_exists($index, $parentArguments);
|
|
|
|
+
|
|
|
|
+ if (strlen($declaredInParent ? $parentArguments[$index] : $arguments[$index]) == 0) {
|
|
|
|
+ $arguments[$declaredInParent ? sprintf('index_%s', $index) : $index] = $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $definition->setArguments($arguments);
|
|
|
|
+ }
|
|
}
|
|
}
|