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

Commit

Permalink
Fixed menus
Browse files Browse the repository at this point in the history
* Added specific menu assignation
* Added priorities to Builders and Menu elements
* Fixed some features for Behat
* Added extension for templating resolving in twig
  • Loading branch information
mmoreram committed Jun 9, 2015
1 parent c262109 commit f90ebd0
Show file tree
Hide file tree
Showing 39 changed files with 321 additions and 69 deletions.
2 changes: 1 addition & 1 deletion app/config/common/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ services:
arguments:
- @templating.engine.twig
- "Layout:_static.html.twig"
- [@elcodi.store_template]
- [@elcodi.store_template_bundle]
2 changes: 1 addition & 1 deletion features/admin/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Feature: Admin login
Scenario: Logged user is redirected to home when goes to login page
Given In admin, I am logged as "[email protected]" - "1234"
When I go to "/admin/login"
Then I should be on "admin/store-setup-wizard"
Then I should be on "/admin"
1 change: 0 additions & 1 deletion features/admin/menu.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Feature: Admin menus
And the page contains a "admin.manufacturer.plural" test attribute
And the page contains a "admin.category.plural" test attribute
And the page contains a "admin.communication.single" test attribute
And the page contains a "admin.shipping_payment.plural" test attribute
And the page contains a "admin.coupon.plural" test attribute
And the page contains a "admin.page.plural" test attribute
And the page contains a "admin.mailing.plural" test attribute
Expand Down
13 changes: 1 addition & 12 deletions src/Elcodi/Admin/CartBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,12 @@ public function build(MenuInterface $menu)
->setCode('shopping-cart')
->setUrl('admin_order_list')
->setTag('order')
->setPriority(16)
->setActiveUrls([
'admin_order_edit',
'admin_customer_order_list',
'admin_customer_order_list',
])
)
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.customer.plural')
->setCode('users')
->setUrl('admin_customer_list')
->setTag('order')
->setActiveUrls([
'admin_customer_edit',
])
);
}
}
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/CartBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 32 }
3 changes: 1 addition & 2 deletions src/Elcodi/Admin/CoreBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function build(MenuInterface $menu)
->setName('admin.menu.design')
->setCode('adjust')
->setTag('design')
->setPriority(1)
)
->addSubnode(
$this
Expand All @@ -74,7 +73,7 @@ public function build(MenuInterface $menu)
->setName('admin.settings.plural')
->setCode('gear')
->setTag('settings')
->setPriority(2)
->setPriority(-32)
);
}
}
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/CoreBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 32 }
52 changes: 52 additions & 0 deletions src/Elcodi/Admin/CouponBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Elcodi package.
*
* Copyright (c) 2014-2015 Elcodi.com
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
* @author Aldo Chiecchia <[email protected]>
* @author Elcodi Team <[email protected]>
*/

namespace Elcodi\Admin\CouponBundle\Builder;

use Elcodi\Component\Menu\Builder\Abstracts\AbstractMenuBuilder;
use Elcodi\Component\Menu\Builder\Interfaces\MenuBuilderInterface;
use Elcodi\Component\Menu\Entity\Menu\Interfaces\MenuInterface;

/**
* Class MenuBuilder
*/
class MenuBuilder extends AbstractMenuBuilder implements MenuBuilderInterface
{
/**
* Build the menu
*
* @param MenuInterface $menu Menu
*/
public function build(MenuInterface $menu)
{
$menu
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.coupon.plural')
->setCode('ticket')
->setUrl('admin_coupon_list')
->setTag('catalog')
->setPriority(16)
->setActiveUrls([
'admin_coupon_edit',
'admin_coupon_new',
])
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function getConfigFiles(array $config)
{
return [
'formTypes',
'menu',
];
}

Expand Down
11 changes: 11 additions & 0 deletions src/Elcodi/Admin/CouponBundle/Resources/config/menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:

#
# Menu builders
#
elcodi_admin.menu_builder.coupon:
class: Elcodi\Admin\CouponBundle\Builder\MenuBuilder
arguments:
- @elcodi.factory.menu_node
tags:
- { name: menu.builder, menu: admin, priority: 32 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/CurrencyBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 16 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/LanguageBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 16 }
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getConfigFiles(array $config)
return [
'formTypes',
'eventListeners',
'menu',
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/PageBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 16 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/PaymentBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function build(MenuInterface $menu)
->setName('admin.settings.section.payment.title')
->setTag('settings')
->setCode('credit-card')
->setPriority(-8)
->setPriority(31)
);
}
}
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/PaymentBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 32 }
15 changes: 11 additions & 4 deletions src/Elcodi/Admin/PluginBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function build(MenuInterface $menu)
->setName('admin.plugin.plural')
->setCode('puzzle-piece')
->setUrl('admin_plugin_list')
->setPriority(1)
->setPriority(-30)
->setTag('settings')
->setActiveUrls([
'admin_plugin_configure',
Expand All @@ -51,11 +51,18 @@ public function build(MenuInterface $menu)
->menuNodeFactory
->create()
->setName('admin.plugin.app_store')
->setCode('puzzle-piece')
->setUrl('admin_plugin_list')
->setPriority(-9999)
->setTag('settings')
->setPriority(9999)
)
)
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.social.single')
->setCode('share-alt')
->setTag('settings')
->setPriority(32)
);
}
}
54 changes: 48 additions & 6 deletions src/Elcodi/Admin/PluginBundle/Builder/PluginMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,68 @@ public function build(MenuInterface $menu)
{
$visiblePlugins = $this->filterVisiblePlugins();

foreach ($visiblePlugins as $visiblePlugin) {
$this
->buildByPluginCategory(
$menu,
$visiblePlugins,
'payment',
'admin.settings.section.payment.title'
)
->buildByPluginCategory(
$menu,
$visiblePlugins,
'shipping',
'admin.carrier.plural'
)
->buildByPluginCategory(
$menu,
$visiblePlugins,
'social',
'admin.social.single'
);
}

/**
* Build by category and place all menu entries inside a family
*
* @param MenuInterface $menu Menu
* @param Plugin[] $plugins Plugins
* @param string $pluginCategory Plugin category
* @param string $parentName Parent name
*
* @return $this Self object
*/
private function buildByPluginCategory(
MenuInterface $menu,
array $plugins,
$pluginCategory,
$parentName
) {
foreach ($plugins as $plugin) {
if ($plugin->getCategory() !== $pluginCategory) {
continue;
}

$pluginConfigurationRoute = $this
->urlGenerator
->generate('admin_plugin_configure', [
'pluginHash' => $visiblePlugin->getHash(),
'pluginHash' => $plugin->getHash(),
]);

$menuNode = $this
->menuNodeFactory
->create()
->setName($visiblePlugin->getConfigurationValue('name'))
->setCode($visiblePlugin->getConfigurationValue('fa_icon'))
->setName($plugin->getConfigurationValue('name'))
->setCode($plugin->getConfigurationValue('fa_icon'))
->setUrl($pluginConfigurationRoute)
->setTag('extra')
->setEnabled(true);

$menu
->findSubnodeByName('admin.plugin.plural')
->findSubnodeByName($parentName)
->addSubnode($menuNode);
}

return $this;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Elcodi/Admin/PluginBundle/Resources/config/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
arguments:
- @elcodi.factory.menu_node
tags:
- { name: menu.builder }
- { name: menu.builder, menu: admin, priority: 32 }

elcodi_admin.menu_builder.plugins:
class: Elcodi\Admin\PluginBundle\Builder\PluginMenuBuilder
Expand All @@ -17,4 +17,4 @@ services:
- @router
- @elcodi.enabled_plugins
tags:
- { name: menu.builder }
- { name: menu.builder, menu: admin, priority: 16 }
41 changes: 15 additions & 26 deletions src/Elcodi/Admin/ProductBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,27 @@ class MenuBuilder extends AbstractMenuBuilder implements MenuBuilderInterface
public function build(MenuInterface $menu)
{
$menu
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.product.plural')
->setCode('gift')
->setUrl('admin_product_list')
->setTag('catalog')
->setActiveUrls([
'admin_product_edit',
'admin_product_new',
])
)
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.coupon.plural')
->setCode('ticket')
->setUrl('admin_coupon_list')
->setTag('catalog')
->setActiveUrls([
'admin_coupon_edit',
'admin_coupon_new',
])
)
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.categorization.single')
->setCode('folder-open')
->setTag('catalog')
->setPriority(32)
->addSubnode(
$this
->menuNodeFactory
->create()
->setName('admin.product.plural')
->setCode('gift')
->setUrl('admin_product_list')
->setTag('catalog')
->setActiveUrls([
'admin_product_edit',
'admin_product_new',
])
)
->addSubnode(
$this
->menuNodeFactory
Expand Down
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/ProductBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 32 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/ShippingBundle/Builder/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function build(MenuInterface $menu)
->setName('admin.carrier.plural')
->setTag('settings')
->setCode('truck')
->setPriority(-4)
->setPriority(30)
);
}
}
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/ShippingBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 32 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/StoreBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 16 }
2 changes: 1 addition & 1 deletion src/Elcodi/Admin/TemplateBundle/Resources/config/menu.yml
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 }
- { name: menu.builder, menu: admin, priority: 16 }
Loading

0 comments on commit f90ebd0

Please sign in to comment.