|
@@ -32,81 +32,73 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
|
*/
|
|
|
public function process(ContainerBuilder $container)
|
|
|
{
|
|
|
- $settings = $this->fixSettings($container);
|
|
|
-
|
|
|
$groups = $groupDefaults = $admins = $classes = array();
|
|
|
|
|
|
$pool = $container->getDefinition('sonata.admin.pool');
|
|
|
|
|
|
- foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
|
|
|
- $definition = $container->getDefinition($id);
|
|
|
+ foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $tags) {
|
|
|
+ foreach ($tags as $attributes) {
|
|
|
+ $definition = $container->getDefinition($id);
|
|
|
|
|
|
- $arguments = $definition->getArguments();
|
|
|
+ $arguments = $definition->getArguments();
|
|
|
|
|
|
- if (strlen($arguments[0]) == 0) {
|
|
|
- $definition->replaceArgument(0, $id);
|
|
|
- }
|
|
|
+ if (strlen($arguments[0]) == 0) {
|
|
|
+ $definition->replaceArgument(0, $id);
|
|
|
+ }
|
|
|
|
|
|
- if (strlen($arguments[2]) == 0) {
|
|
|
- $definition->replaceArgument(2, 'SonataAdminBundle:CRUD');
|
|
|
- }
|
|
|
+ if (strlen($arguments[2]) == 0) {
|
|
|
+ $definition->replaceArgument(2, 'SonataAdminBundle:CRUD');
|
|
|
+ }
|
|
|
|
|
|
- $this->applyDefaults($container, $id, $attributes, $settings);
|
|
|
+ $this->applyDefaults($container, $id, $attributes);
|
|
|
|
|
|
- $arguments = $definition->getArguments();
|
|
|
- if (preg_match('/%(.*)%/', $arguments[1], $matches)) {
|
|
|
- $class = $container->getParameter($matches[1]);
|
|
|
- } else {
|
|
|
- $class = $arguments[1];
|
|
|
- }
|
|
|
+ $arguments = $definition->getArguments();
|
|
|
|
|
|
- $admins[] = $id;
|
|
|
- $classes[$class] = $id;
|
|
|
+ $admins[] = $id;
|
|
|
+ $classes[$arguments[1]] = $id;
|
|
|
|
|
|
- $showInDashBord = (boolean)(isset($attributes[0]['show_in_dashboard']) ? $attributes[0]['show_in_dashboard'] : true);
|
|
|
- if (!$showInDashBord) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $showInDashBord = (boolean)(isset($attributes['show_in_dashboard']) ? $attributes['show_in_dashboard'] : true);
|
|
|
+ if (!$showInDashBord) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- $group_name = isset($attributes[0]['group']) ? $attributes[0]['group'] : 'default';
|
|
|
+ $groupName = isset($attributes['group']) ? $attributes['group'] : 'default';
|
|
|
|
|
|
- if (!isset($groupDefaults[$group_name])) {
|
|
|
- $groupDefaults[$group_name] = array(
|
|
|
- 'label' => $group_name
|
|
|
- );
|
|
|
- }
|
|
|
+ if (!isset($groupDefaults[$groupName])) {
|
|
|
+ $groupDefaults[$groupName] = array(
|
|
|
+ 'label' => $groupName
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
- $groupDefaults[$group_name]['items'][] = $id;
|
|
|
+ $groupDefaults[$groupName]['items'][] = $id;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (!empty($settings['dashboard_groups'])) {
|
|
|
-
|
|
|
- $groups = $settings['dashboard_groups'];
|
|
|
-
|
|
|
- foreach ($groups as $group_name => $group) {
|
|
|
+ $dashboardGroupsSettings = $container->getParameter('sonata.admin.configuration.dashboard_groups');
|
|
|
+ if (!empty($dashboardGroupsSettings)) {
|
|
|
+ $groups = $dashboardGroupsSettings;
|
|
|
|
|
|
- if (!isset($groupDefaults[$group_name])) {
|
|
|
- $groupDefaults[$group_name] = array(
|
|
|
+ foreach ($dashboardGroupsSettings as $groupName => $group) {
|
|
|
+ if (!isset($groupDefaults[$groupName])) {
|
|
|
+ $groupDefaults[$groupName] = array(
|
|
|
'items' => array(),
|
|
|
- 'label' => $group_name
|
|
|
+ 'label' => $groupName
|
|
|
);
|
|
|
}
|
|
|
|
|
|
if (empty($group['items'])) {
|
|
|
- $groups[$group_name]['items'] = $groupDefaults[$group_name]['items'];
|
|
|
+ $groups[$groupName]['items'] = $groupDefaults[$groupName]['items'];
|
|
|
}
|
|
|
|
|
|
if (empty($group['label'])) {
|
|
|
- $groups[$group_name]['label'] = $groupDefaults[$group_name]['label'];
|
|
|
+ $groups[$groupName]['label'] = $groupDefaults[$groupName]['label'];
|
|
|
}
|
|
|
|
|
|
- if (!empty($groups[$group_name]['item_adds'])) {
|
|
|
- $groups[$group_name]['items'] = array_merge($groupDefaults[$group_name]['items'], $groups[$group_name]['item_adds']);
|
|
|
+ if (!empty($group['item_adds'])) {
|
|
|
+ $group['items'] = array_merge($groupDefaults[$groupName]['items'], $group['item_adds']);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
+ } else {
|
|
|
$groups = $groupDefaults;
|
|
|
}
|
|
|
|
|
@@ -118,47 +110,24 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
|
$routeLoader->replaceArgument(1, $admins);
|
|
|
}
|
|
|
|
|
|
- public function fixSettings($container)
|
|
|
- {
|
|
|
- $pool = $container->getDefinition('sonata.admin.pool');
|
|
|
-
|
|
|
- // not very clean but don't know how to do that for now
|
|
|
- $settings = false;
|
|
|
- $methods = $pool->getMethodCalls();
|
|
|
- foreach ($methods as $pos => $calls) {
|
|
|
- if ($calls[0] == '__hack__') {
|
|
|
- $settings = $calls[1];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($settings) {
|
|
|
- unset($methods[$pos]);
|
|
|
- }
|
|
|
-
|
|
|
- $pool->setMethodCalls($methods);
|
|
|
-
|
|
|
- return $settings;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Apply the default values required by the AdminInterface to the Admin service definition
|
|
|
*
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
|
|
- * @param $serviceId
|
|
|
+ * @param string $serviceId
|
|
|
* @param array $attributes
|
|
|
- * @param array $settings
|
|
|
* @return \Symfony\Component\DependencyInjection\Definition
|
|
|
*/
|
|
|
- public function applyDefaults(ContainerBuilder $container, $serviceId, array $attributes = array(), array $settings = array())
|
|
|
+ public function applyDefaults(ContainerBuilder $container, $serviceId, array $attributes = array())
|
|
|
{
|
|
|
$definition = $container->getDefinition($serviceId);
|
|
|
+ $settings = $container->getParameter('sonata.admin.configuration.admin_services');
|
|
|
|
|
|
$definition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
|
|
|
|
|
|
- $manager_type = $attributes[0]['manager_type'];
|
|
|
+ $manager_type = $attributes['manager_type'];
|
|
|
|
|
|
- $addServices = isset($settings['admin_services'][$serviceId]) ? $settings['admin_services'][$serviceId] : false;
|
|
|
+ $addServices = isset($settings[$serviceId]) ? $settings[$serviceId] : array();
|
|
|
|
|
|
$defaultAddServices = array(
|
|
|
'model_manager' => sprintf('sonata.admin.manager.%s', $manager_type),
|
|
@@ -188,8 +157,8 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
|
|
|
|
if (isset($service['label'])) {
|
|
|
$label = $service['label'];
|
|
|
- } elseif (isset($attributes[0]['label'])) {
|
|
|
- $label = $attributes[0]['label'];
|
|
|
+ } elseif (isset($attributes['label'])) {
|
|
|
+ $label = $attributes['label'];
|
|
|
} else {
|
|
|
$label = '-';
|
|
|
}
|
|
@@ -198,7 +167,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
|
|
|
$definition->addMethodCall('configure');
|
|
|
|
|
|
if (!$definition->hasMethodCall('setTemplates')) {
|
|
|
- $definition->addMethodCall('setTemplates', array($settings['templates']));
|
|
|
+ $definition->addMethodCall('setTemplates', array('%sonata.admin.configuration.templates%'));
|
|
|
}
|
|
|
|
|
|
return $definition;
|