From d5a1992d56b3337295c24fbad5a5216798fe8769 Mon Sep 17 00:00:00 2001 From: mmoreram Date: Sat, 13 Jun 2015 18:59:03 +0200 Subject: [PATCH] Unified all plugin lists controller * A menuNode url can be defined as well with an array of name-parameters --- .../views/Navs/side_elements.html.twig | 12 ++- .../views/Navs/side_elements_mobile.html.twig | 14 +++- .../Builder/PluginCategoryMenuBuilder.php | 78 ++++++++++--------- .../Builder/PluginMenuBuilder.php | 28 ++----- .../Controller/PluginController.php | 24 ++---- .../Resources/config/categoriesMenu.yml | 2 +- .../Resources/config/pluginMenu.yml | 1 - 7 files changed, 77 insertions(+), 82 deletions(-) diff --git a/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements.html.twig b/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements.html.twig index 3b18ecb8..6ae6d176 100644 --- a/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements.html.twig +++ b/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements.html.twig @@ -10,7 +10,11 @@ {% macro showNode(node, route) %}
  • {% if node.subnodes|length == 0 %} - + {% set node_url = node.url is iterable + ? url(node.url[0], node.url[1]) + : url(node.url) + %} + {% else %} @@ -30,7 +34,11 @@ diff --git a/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements_mobile.html.twig b/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements_mobile.html.twig index e408207d..98df887a 100644 --- a/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements_mobile.html.twig +++ b/src/Elcodi/Admin/CoreBundle/Resources/views/Navs/side_elements_mobile.html.twig @@ -9,8 +9,12 @@ {% macro showNode(node, route) %}
  • - {% if generate_url(node.url) != '' %} - + {% if node.subnodes|length == 0 %} + {% set node_url = node.url is iterable + ? url(node.url[0], node.url[1]) + : url(node.url) + %} + {% else %} @@ -30,7 +34,11 @@ diff --git a/src/Elcodi/Admin/PluginBundle/Builder/PluginCategoryMenuBuilder.php b/src/Elcodi/Admin/PluginBundle/Builder/PluginCategoryMenuBuilder.php index 796b9e48..f73d3eaf 100644 --- a/src/Elcodi/Admin/PluginBundle/Builder/PluginCategoryMenuBuilder.php +++ b/src/Elcodi/Admin/PluginBundle/Builder/PluginCategoryMenuBuilder.php @@ -33,43 +33,49 @@ class PluginCategoryMenuBuilder extends AbstractMenuBuilder implements MenuBuild */ public function build(MenuInterface $menu) { - $plugin = $menu->findSubnodeByName('plugin_type.social'); - if ($plugin) { - $plugin - ->addSubnode( - $this - ->menuNodeFactory - ->create() - ->setName('admin.plugin.social_store') - ->setUrl('admin_plugin_social_list') - ->setPriority(9999) - ); - } + $menu + ->findSubnodeByName('plugin_type.social') + ->addSubnode( + $this + ->menuNodeFactory + ->create() + ->setName('admin.plugin.social_store') + ->setUrl([ + 'admin_plugin_categorized_list', [ + 'category' => 'social', + ], + ]) + ->setPriority(9999) + ); - $plugin = $menu->findSubnodeByName('plugin_type.payment'); - if ($plugin) { - $plugin - ->addSubnode( - $this - ->menuNodeFactory - ->create() - ->setName('admin.plugin.payment_store') - ->setUrl('admin_plugin_payment_list') - ->setPriority(9999) - ); - } + $menu + ->findSubnodeByName('plugin_type.payment') + ->addSubnode( + $this + ->menuNodeFactory + ->create() + ->setName('admin.plugin.payment_store') + ->setUrl([ + 'admin_plugin_categorized_list', [ + 'category' => 'payment', + ], + ]) + ->setPriority(9999) + ); - $plugin = $menu->findSubnodeByName('plugin_type.shipping'); - if ($plugin) { - $plugin - ->addSubnode( - $this - ->menuNodeFactory - ->create() - ->setName('admin.plugin.shipping_store') - ->setUrl('admin_plugin_shipping_list') - ->setPriority(9999) - ); - } + $menu + ->findSubnodeByName('plugin_type.shipping') + ->addSubnode( + $this + ->menuNodeFactory + ->create() + ->setName('admin.plugin.shipping_store') + ->setUrl([ + 'admin_plugin_categorized_list', [ + 'category' => 'shipping', + ], + ]) + ->setPriority(9999) + ); } } diff --git a/src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php b/src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php index 3ab85a0a..1bd3b73f 100644 --- a/src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php +++ b/src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php @@ -17,8 +17,6 @@ namespace Elcodi\Admin\PluginBundle\Builder; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; - use Elcodi\Component\Menu\Builder\Interfaces\MenuBuilderInterface; use Elcodi\Component\Menu\Entity\Menu\Interfaces\MenuInterface; use Elcodi\Component\Menu\Entity\Menu\Interfaces\NodeInterface; @@ -37,13 +35,6 @@ class PluginMenuBuilder implements MenuBuilderInterface */ protected $menuNodeFactory; - /** - * @var UrlGeneratorInterface - * - * Url generator - */ - protected $urlGenerator; - /** * @var Plugin[] * @@ -54,17 +45,14 @@ class PluginMenuBuilder implements MenuBuilderInterface /** * Constructor * - * @param NodeFactory $menuNodeFactory Menu node factory - * @param UrlGeneratorInterface $urlGenerator Url generator - * @param array $enabledPlugins Enabled Plugins + * @param NodeFactory $menuNodeFactory Menu node factory + * @param array $enabledPlugins Enabled Plugins */ public function __construct( NodeFactory $menuNodeFactory, - UrlGeneratorInterface $urlGenerator, array $enabledPlugins ) { $this->menuNodeFactory = $menuNodeFactory; - $this->urlGenerator = $urlGenerator; $this->enabledPlugins = $enabledPlugins; } @@ -114,18 +102,16 @@ private function buildByPluginCategory( continue; } - $pluginConfigurationRoute = $this - ->urlGenerator - ->generate('admin_plugin_configure', [ - 'pluginHash' => $plugin->getHash(), - ]); - $node = $this ->menuNodeFactory ->create() ->setName($plugin->getConfigurationValue('name')) ->setCode($plugin->getConfigurationValue('fa_icon')) - ->setUrl($pluginConfigurationRoute) + ->setUrl([ + 'admin_plugin_configure', [ + 'pluginHash' => $plugin->getHash(), + ], + ]) ->setEnabled(true); $parentNode->addSubnode($node); diff --git a/src/Elcodi/Admin/PluginBundle/Controller/PluginController.php b/src/Elcodi/Admin/PluginBundle/Controller/PluginController.php index 13c34e76..6facab7c 100644 --- a/src/Elcodi/Admin/PluginBundle/Controller/PluginController.php +++ b/src/Elcodi/Admin/PluginBundle/Controller/PluginController.php @@ -51,23 +51,8 @@ class PluginController extends AbstractAdminController * ) * * @Route( - * path = "s/payment", - * name = "admin_plugin_payment_list", - * defaults = { "category": "payment" }, - * methods = {"GET"} - * ) - * - * @Route( - * path = "s/shipping", - * name = "admin_plugin_shipping_list", - * defaults = { "category": "shipping" }, - * methods = {"GET"} - * ) - * - * @Route( - * path = "s/social", - * name = "admin_plugin_social_list", - * defaults = { "category": "social" }, + * path = "s/{category}", + * name = "admin_plugin_categorized_list", * methods = {"GET"} * ) * @@ -85,7 +70,10 @@ public function listAction($category = null) $plugins = $this ->get('elcodi.repository.plugin') - ->findBy($criteria, [ 'category' => 'ASC' ]); + ->findBy( + $criteria, + [ 'category' => 'ASC' ] + ); return [ 'plugins' => $plugins, diff --git a/src/Elcodi/Admin/PluginBundle/Resources/config/categoriesMenu.yml b/src/Elcodi/Admin/PluginBundle/Resources/config/categoriesMenu.yml index 657e559f..f9b6c937 100644 --- a/src/Elcodi/Admin/PluginBundle/Resources/config/categoriesMenu.yml +++ b/src/Elcodi/Admin/PluginBundle/Resources/config/categoriesMenu.yml @@ -8,4 +8,4 @@ services: arguments: - @elcodi.factory.menu_node tags: - - { name: menu.builder, menu: admin, priority: 16 } + - { name: menu.builder, menu: admin, priority: 8 } diff --git a/src/Elcodi/Admin/PluginBundle/Resources/config/pluginMenu.yml b/src/Elcodi/Admin/PluginBundle/Resources/config/pluginMenu.yml index d5ad05cd..60618594 100644 --- a/src/Elcodi/Admin/PluginBundle/Resources/config/pluginMenu.yml +++ b/src/Elcodi/Admin/PluginBundle/Resources/config/pluginMenu.yml @@ -7,7 +7,6 @@ services: class: Elcodi\Admin\PluginBundle\Builder\PluginMenuBuilder arguments: - @elcodi.factory.menu_node - - @router - @elcodi.enabled_plugins tags: - { name: menu.builder, menu: admin, priority: 16 }