-
Notifications
You must be signed in to change notification settings - Fork 1
/
MenuServiceProvider.php
73 lines (61 loc) · 2.28 KB
/
MenuServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace App\ServiceProvider;
use Knp\Menu\MenuFactory;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class MenuServiceProvider implements ServiceProviderInterface {
public function register(Container $app) {
$app['admin_menu'] = function($app) {
/** @var MenuFactory $factory */
$factory = $app['knp_menu.factory'];
$menu = $factory->createItem('Admin menu')
->setChildrenAttributes([
'class' => 'nav navbar-nav'
]);
$menu->addChild('Dashboard', [
'route' => 'dashboard'
])
->setAttribute('icon', 'fa fa-dashboard');
$menu->addChild('Users', [
'route' => 'users'
])
->setAttribute('icon', 'fa fa-users');
$menu->addChild('Service providers', [
'route' => 'service_providers'
])
->setAttribute('icon', 'fa fa-files-o');
/*$menu->addChild('Settings', [
'route' => 'admin_settings'
])
->setAttribute('icon', 'fa fa-cogs');*/
return $menu;
};
$app['user_menu'] = function($app) {
/** @var TokenInterface $token */
$token = $app['security.token_storage']->getToken();
/** @var UserInterface $user */
$user = $token->getUser();
/** @var MenuFactory $factory */
$factory = $app['knp_menu.factory'];
$menu = $factory->createItem('User menu')
->setChildrenAttributes([
'class' => 'nav navbar-nav navbar-right'
]);
$menu->addChild($user->getUsername(), [
'route' => 'profile'
])
->setAttribute('icon', 'fa fa-user');
$menu->addChild('Logout', [
'route' => 'logout'
])
->setAttribute('icon', 'fa sign-out');
return $menu;
};
$app['knp_menu.menus'] = [
'admin_menu' => 'admin_menu',
'user_menu' => 'user_menu'
];
}
}