Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Commit

Permalink
Unified all plugin lists controller
Browse files Browse the repository at this point in the history
* A menuNode url can be defined as well with an array of name-parameters
  • Loading branch information
mmoreram committed Jun 13, 2015
1 parent 6fadc54 commit d5a1992
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
{% macro showNode(node, route) %}
<li class="{% if node.isActive(route) %}active{% endif %}{% if node.subnodes|length %}parent{% endif %}" data-test="{{ node.name }}">
{% if node.subnodes|length == 0 %}
<a href="{{ generate_url(node.url) }}">
{% set node_url = node.url is iterable
? url(node.url[0], node.url[1])
: url(node.url)
%}
<a href="{{ node_url }}">
{% else %}
<a href="#{{ node.name|md5 }}" data-fc-modules="toggle">
<i class="icon-caret-down fl-r"></i>
Expand All @@ -30,7 +34,11 @@
<ul id="{{ node.name|md5 }}" {% if not node.isExpanded(route) %}class="hidden"{% endif %}>
{% endif %}
<li {% if subnode.isActive(route) %}class="active"{% endif %} data-test="{{ subnode.name }}">
<a href="{{ generate_url(subnode.url) }}" class="pl-l"><i class="icon-angle-right"></i> {{ subnode.name|trans }}</a>
{% set subnode_url = subnode.url is iterable
? url(subnode.url[0], subnode.url[1])
: url(subnode.url)
%}
<a href="{{ subnode_url }}" class="pl-l"><i class="icon-angle-right"></i> {{ subnode.name|trans }}</a>
</li>
{% if loop.last %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

{% macro showNode(node, route) %}
<li class="{% if node.isActive(route) %}active{% endif %}{% if node.subnodes|length %}parent{% endif %}" data-test="{{ node.name }}">
{% if generate_url(node.url) != '' %}
<a href="{{ 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)
%}
<a href="{{ node_url }}">
{% else %}
<a href="#{{ node.name|md5 }}" data-fc-modules="toggle">
<i class="icon-caret-down fl-r"></i>
Expand All @@ -30,7 +34,11 @@
<ul id="{{ node.name|md5 }}" {% if not node.isExpanded(route) %}class="hidden"{% endif %}>
{% endif %}
<li {% if subnode.isActive(route) %}class="active"{% endif %} data-test="{{ subnode.name }}">
<a href="{{ generate_url(subnode.url) }}" class="pl-l"><i class="icon-angle-right"></i> {{ subnode.name|trans }}</a>
{% set subnode_url = subnode.url is iterable
? url(subnode.url[0], subnode.url[1])
: url(subnode.url)
%}
<a href="{{ subnode_url }}" class="pl-l"><i class="icon-angle-right"></i> {{ subnode.name|trans }}</a>
</li>
{% if loop.last %}
</ul>
Expand Down
78 changes: 42 additions & 36 deletions src/Elcodi/Admin/PluginBundle/Builder/PluginCategoryMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
28 changes: 7 additions & 21 deletions src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,13 +35,6 @@ class PluginMenuBuilder implements MenuBuilderInterface
*/
protected $menuNodeFactory;

/**
* @var UrlGeneratorInterface
*
* Url generator
*/
protected $urlGenerator;

/**
* @var Plugin[]
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
24 changes: 6 additions & 18 deletions src/Elcodi/Admin/PluginBundle/Controller/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
* )
*
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit d5a1992

Please sign in to comment.