Explorar el Código

Move menu-related methods to their own interface

Grégoire Paris hace 8 años
padre
commit
82174fefca
Se han modificado 2 ficheros con 56 adiciones y 35 borrados
  1. 1 35
      Admin/AdminInterface.php
  2. 55 0
      Admin/MenuBuilderInterface.php

+ 1 - 35
Admin/AdminInterface.php

@@ -11,8 +11,6 @@
 
 namespace Sonata\AdminBundle\Admin;
 
-use Knp\Menu\FactoryInterface as MenuFactoryInterface;
-use Knp\Menu\ItemInterface;
 use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
 use Sonata\AdminBundle\Builder\FormContractorInterface;
 use Sonata\AdminBundle\Builder\ListBuilderInterface;
@@ -34,7 +32,7 @@ use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
 /**
  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  */
-interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHookProviderInterface
+interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface
 {
     /**
      * @param FormContractorInterface $formContractor
@@ -398,16 +396,6 @@ interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHoo
      */
     public function getExtensions();
 
-    /**
-     * @param \Knp\Menu\FactoryInterface $menuFactory
-     */
-    public function setMenuFactory(MenuFactoryInterface $menuFactory);
-
-    /**
-     * @return \Knp\Menu\FactoryInterface
-     */
-    public function getMenuFactory();
-
     /**
      * @param RouteBuilderInterface $routeBuilder
      */
@@ -806,28 +794,6 @@ interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHoo
      */
     public function getTranslationLabel($label, $context = '', $type = '');
 
-    /**
-     * NEXT_MAJOR: remove this method.
-     *
-     * @param string         $action
-     * @param AdminInterface $childAdmin
-     *
-     * @return ItemInterface|bool
-     *
-     * @deprecated Use buildTabMenu instead
-     */
-    public function buildSideMenu($action, AdminInterface $childAdmin = null);
-
-    /**
-     * Build the tab menu related to the current action.
-     *
-     * @param string         $action
-     * @param AdminInterface $childAdmin
-     *
-     * @return ItemInterface|bool
-     */
-    public function buildTabMenu($action, AdminInterface $childAdmin = null);
-
     /**
      * @param $object
      *

+ 55 - 0
Admin/MenuBuilderInterface.php

@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Admin;
+
+use Knp\Menu\FactoryInterface as MenuFactoryInterface;
+use Knp\Menu\ItemInterface;
+
+/**
+ * This interface can be implemented by admins that need to build menus.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface MenuBuilderInterface
+{
+    /**
+     * @param MenuFactoryInterface $menuFactory
+     */
+    public function setMenuFactory(MenuFactoryInterface $menuFactory);
+
+    /**
+     * @return MenuFactoryInterface
+     */
+    public function getMenuFactory();
+
+    /**
+     * NEXT_MAJOR: remove this method.
+     *
+     * @param string         $action
+     * @param AdminInterface $childAdmin
+     *
+     * @return ItemInterface|bool
+     *
+     * @deprecated Use buildTabMenu instead
+     */
+    public function buildSideMenu($action, AdminInterface $childAdmin = null);
+
+    /**
+     * Build the tab menu related to the current action.
+     *
+     * @param string         $action
+     * @param AdminInterface $childAdmin
+     *
+     * @return ItemInterface|bool
+     */
+    public function buildTabMenu($action, AdminInterface $childAdmin = null);
+}