Pārlūkot izejas kodu

Added support for KnpMenu v2-alpha /!\ UNSTABLE

Hugo Briand 11 gadi atpakaļ
vecāks
revīzija
6fc4f0400e

+ 8 - 3
Admin/Admin.php

@@ -1199,6 +1199,14 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         return $this->routeGenerator->generateUrl($this, $name, $parameters, $absolute);
         return $this->routeGenerator->generateUrl($this, $name, $parameters, $absolute);
     }
     }
 
 
+    /**
+     * {@inheritdoc}
+     */
+    public function generateMenuUrl($name, array $parameters = array(), $absolute = false)
+    {
+        return $this->routeGenerator->generateMenuUrl($this, $name,$parameters, $absolute);
+    }
+
     /**
     /**
      * @param array $templates
      * @param array $templates
      *
      *
@@ -1422,7 +1430,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
 
         $menu = $this->menuFactory->createItem('root');
         $menu = $this->menuFactory->createItem('root');
         $menu->setChildrenAttribute('class', 'nav nav-list');
         $menu->setChildrenAttribute('class', 'nav nav-list');
-        $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo());
 
 
         $this->configureSideMenu($menu, $action, $childAdmin);
         $this->configureSideMenu($menu, $action, $childAdmin);
 
 
@@ -2058,8 +2065,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             $menu = $menu->addChild(
             $menu = $menu->addChild(
                 $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
                 $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
             );
             );
-        } else {
-            $menu->getBreadcrumbsArray();
         }
         }
 
 
         return $this->breadcrumbs[$action] = $menu;
         return $this->breadcrumbs[$action] = $menu;

+ 11 - 0
Admin/AdminInterface.php

@@ -165,6 +165,17 @@ interface AdminInterface
      */
      */
     public function generateUrl($name, array $parameters = array(), $absolute = false);
     public function generateUrl($name, array $parameters = array(), $absolute = false);
 
 
+    /**
+     * Generates an url for the given parameters
+     *
+     * @param string $name
+     * @param array  $parameters
+     * @param bool   $absolute
+     *
+     * @return string return a complete url
+     */
+    public function generateMenuUrl($name, array $parameters = array(), $absolute = false);
+
     /**
     /**
      * @return \Sonata\AdminBundle\Model\ModelManagerInterface;
      * @return \Sonata\AdminBundle\Model\ModelManagerInterface;
      */
      */

+ 4 - 0
CHANGELOG.md

@@ -1,6 +1,10 @@
 CHANGELOG
 CHANGELOG
 =========
 =========
 
 
+### 2013-12-27
+
+* [BC BREAK] Added KnpMenuBundle v2.x compatibility, ``buildSideMenu`` must now use the ``Admin::generateMenuUrl`` method to generate the route arguments for the KnpMenu options.
+
 ### 2013-12-14
 ### 2013-12-14
 
 
 * [BC BREAK] Added the ``getTranslationLabel`` method to AdminInterface
 * [BC BREAK] Added the ``getTranslationLabel`` method to AdminInterface

+ 23 - 1
Route/DefaultRouteGenerator.php

@@ -49,6 +49,24 @@ class DefaultRouteGenerator implements RouteGeneratorInterface
      * @return string
      * @return string
      */
      */
     public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
     public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
+    {
+        $arrayRoute = $this->generateMenuUrl($admin, $name, $parameters, $absolute);
+
+        return $this->router->generate($arrayRoute['route'], $arrayRoute['routeParameters'], $arrayRoute['routeAbsolute']);
+    }
+
+    /**
+     * Generates KNPMenu array parameters for menu route
+     *
+     * @param AdminInterface $admin
+     * @param string         $name
+     * @param array          $parameters
+     * @param bool           $absolute
+     *
+     * @return array
+     * @throws \RuntimeException
+     */
+    public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
     {
     {
         if (!$admin->isChild()) {
         if (!$admin->isChild()) {
             if (strpos($name, '.')) {
             if (strpos($name, '.')) {
@@ -98,6 +116,10 @@ class DefaultRouteGenerator implements RouteGeneratorInterface
             throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
             throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
         }
         }
 
 
-        return $this->router->generate($route->getDefault('_sonata_name'), $parameters, $absolute);
+        return array(
+            'route'           => $route->getDefault('_sonata_name'),
+            'routeParameters' => $parameters,
+            'routeAbsolute'   => $absolute
+        );
     }
     }
 }
 }

+ 10 - 0
Route/RouteGeneratorInterface.php

@@ -24,6 +24,16 @@ interface RouteGeneratorInterface
      */
      */
     public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false);
     public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false);
 
 
+    /**
+     * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
+     * @param string                                   $name
+     * @param array                                    $parameters
+     * @param bool                                     $absolute
+     *
+     * @return string
+     */
+    public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false);
+
     /**
     /**
      * @param string $name
      * @param string $name
      * @param array  $parameters
      * @param array  $parameters

+ 2 - 1
composer.json

@@ -29,7 +29,8 @@
         "sensio/generator-bundle": "~2.2",
         "sensio/generator-bundle": "~2.2",
         "twig/twig": "~1.12",
         "twig/twig": "~1.12",
         "twig/extensions": "~1.0",
         "twig/extensions": "~1.0",
-        "knplabs/knp-menu-bundle": "~1.1",
+        "knplabs/knp-menu-bundle": "~2.0@dev",
+        "knplabs/knp-menu": "~2.0@dev",
         "sonata-project/jquery-bundle": "1.8.*",
         "sonata-project/jquery-bundle": "1.8.*",
         "sonata-project/exporter": "1.*",
         "sonata-project/exporter": "1.*",
         "sonata-project/block-bundle": "~2.2,>=2.2.7",
         "sonata-project/block-bundle": "~2.2,>=2.2.7",