Преглед на файлове

add params route absolute for the generate menu

andrey1s преди 9 години
родител
ревизия
42b8a01fd6

+ 5 - 4
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -93,10 +93,11 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
                 }
 
                 $groupDefaults[$resolvedGroupName]['items'][] = array(
-                    'admin'        => $id,
-                    'label'        => !empty($attributes['label']) ? $attributes['label'] : '',
-                    'route'        => '',
-                    'route_params' => array(),
+                    'admin'          => $id,
+                    'label'          => !empty($attributes['label']) ? $attributes['label'] : '',
+                    'route'          => '',
+                    'route_params'   => array(),
+                    'route_absolute' => true,
                 );
             }
         }

+ 9 - 4
DependencyInjection/Configuration.php

@@ -142,10 +142,11 @@ class Configuration implements ConfigurationInterface
                                                         $items[$key]['admin'] = '';
                                                     } else {
                                                         $items[$key] = array(
-                                                            'admin'        => $item,
-                                                            'label'        => '',
-                                                            'route'        => '',
-                                                            'route_params' => array(),
+                                                            'admin'          => $item,
+                                                            'label'          => '',
+                                                            'route'          => '',
+                                                            'route_params'   => array(),
+                                                            'route_absolute' => true,
                                                         );
                                                     }
                                                 }
@@ -161,6 +162,10 @@ class Configuration implements ConfigurationInterface
                                                 ->arrayNode('route_params')
                                                     ->prototype('scalar')->end()
                                                 ->end()
+                                                ->booleanNode('route_absolute')
+                                                    ->info('Whether the generated url should be absolute')
+                                                    ->defaultTrue()
+                                                ->end()
                                             ->end()
                                         ->end()
                                     ->end()

+ 2 - 1
Menu/Provider/GroupMenuProvider.php

@@ -73,7 +73,7 @@ class GroupMenuProvider implements MenuProviderInterface
                 }
 
                 $label = $admin->getLabel();
-                $options = $admin->generateMenuUrl('list');
+                $options = $admin->generateMenuUrl('list', array(), $item['route_absolute']);
                 $options['extras'] = array(
                     'translation_domain' => $admin->getTranslationDomain(),
                     'admin'              => $admin,
@@ -83,6 +83,7 @@ class GroupMenuProvider implements MenuProviderInterface
                 $options = array(
                     'route'           => $item['route'],
                     'routeParameters' => $item['route_params'],
+                    'routeAbsolute'   => $item['route_absolute'],
                     'extras'          => array(
                         'translation_domain' => $group['label_catalogue'],
                     ),

+ 24 - 19
Tests/DependencyInjection/ConfigurationTest.php

@@ -117,9 +117,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
                             'item1',
                             'item2',
                             array(
-                                'label'        => 'fooLabel',
-                                'route'        => 'fooRoute',
-                                'route_params' => array('bar' => 'foo'),
+                                'label'          => 'fooLabel',
+                                'route'          => 'fooRoute',
+                                'route_params'   => array('bar' => 'foo'),
+                                'route_absolute' => true,
                             ),
                             array(
                                 'label' => 'barLabel',
@@ -135,37 +136,41 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
         $this->assertSame(
             $config['dashboard']['groups']['bar']['items'][0],
             array(
-                'admin'        => 'item1',
-                'label'        => '',
-                'route'        => '',
-                'route_params' => array(),
+                'admin'          => 'item1',
+                'label'          => '',
+                'route'          => '',
+                'route_params'   => array(),
+                'route_absolute' => true,
             )
         );
         $this->assertSame(
             $config['dashboard']['groups']['bar']['items'][1],
             array(
-                'admin'        => 'item2',
-                'label'        => '',
-                'route'        => '',
-                'route_params' => array(),
+                'admin'          => 'item2',
+                'label'          => '',
+                'route'          => '',
+                'route_params'   => array(),
+                'route_absolute' => true,
             )
         );
         $this->assertSame(
             $config['dashboard']['groups']['bar']['items'][2],
             array(
-                'label'        => 'fooLabel',
-                'route'        => 'fooRoute',
-                'route_params' => array('bar' => 'foo'),
-                'admin'        => '',
+                'label'          => 'fooLabel',
+                'route'          => 'fooRoute',
+                'route_params'   => array('bar' => 'foo'),
+                'route_absolute' => true,
+                'admin'          => '',
             )
         );
         $this->assertSame(
             $config['dashboard']['groups']['bar']['items'][3],
             array(
-                'label'        => 'barLabel',
-                'route'        => 'barRoute',
-                'route_params' => array(),
-                'admin'        => '',
+                'label'          => 'barLabel',
+                'route'          => 'barRoute',
+                'route_params'   => array(),
+                'admin'          => '',
+                'route_absolute' => true,
             )
         );
     }

+ 18 - 7
Tests/Menu/Provider/GroupMenuProviderTest.php

@@ -101,8 +101,9 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
         $this->assertSame('foo', $menu->getName());
 
         $children = $menu->getChildren();
-        $this->assertCount(1, $children);
+        $this->assertCount(2, $children);
         $this->assertArrayHasKey('foo_admin_label', $children);
+        $this->assertArrayHasKey('route_label', $children);
         $this->assertInstanceOf('Knp\Menu\MenuItem', $menu['foo_admin_label']);
         $this->assertSame('foo_admin_label', $menu['foo_admin_label']->getLabel());
     }
@@ -112,7 +113,7 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
      *
      * @dataProvider getAdminGroups
      */
-    public function testGetKnpMenuWithNoListRoute(array $adminGroups)
+    public function testGetKnpMenuWithListRoute(array $adminGroups)
     {
         $this->pool->expects($this->once())
             ->method('getInstance')
@@ -129,7 +130,8 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
 
         $this->assertInstanceOf('Knp\Menu\ItemInterface', $menu);
         $this->assertArrayNotHasKey('foo_admin_label', $menu->getChildren());
-        $this->assertCount(0, $menu->getChildren());
+        $this->assertArrayHasKey('route_label', $menu->getChildren());
+        $this->assertCount(1, $menu->getChildren());
     }
 
     /**
@@ -137,7 +139,7 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
      *
      * @dataProvider getAdminGroups
      */
-    public function testGetKnpMenuWithNotGrantedList(array $adminGroups)
+    public function testGetKnpMenuWithGrantedList(array $adminGroups)
     {
         $this->pool->expects($this->once())
             ->method('getInstance')
@@ -154,7 +156,8 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
 
         $this->assertInstanceOf('Knp\Menu\ItemInterface', $menu);
         $this->assertArrayNotHasKey('foo_admin_label', $menu->getChildren());
-        $this->assertCount(0, $menu->getChildren());
+        $this->assertArrayHasKey('route_label', $menu->getChildren());
+        $this->assertCount(1, $menu->getChildren());
     }
 
     /**
@@ -170,8 +173,16 @@ class GroupMenuProviderTest extends \PHPUnit_Framework_TestCase
                     'label_catalogue' => 'SonataAdminBundle',
                     'items'           => array(
                         array(
-                            'admin' => 'sonata_admin_foo_service',
-                            'label' => 'fooLabel',
+                            'admin'          => 'sonata_admin_foo_service',
+                            'label'          => 'fooLabel',
+                            'route_absolute' => true,
+                        ),
+                        array(
+                            'admin'          => '',
+                            'label'          => 'route_label',
+                            'route'          => 'FooRoute',
+                            'route_params'   => array('foo' => 'bar'),
+                            'route_absolute' => true,
                         ),
                     ),
                     'item_adds'       => array(),