Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Add KnpMenu, fix README file
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd authored and venyii committed Feb 12, 2015
1 parent 45f3dc5 commit f078ea5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,7 @@ Installation
------------

1. Clone the repository
2. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and edit the relevant values for your setup.
2. Edit `app/config/parameters.yml` and change the relevant values for your setup.
3. Install dependencies: `php composer.phar install`
4. Run `app/console doctrine:schema:create` to setup the DB.
5. Run `app/console assets:install web` to deploy the assets on the web dir.
Expand Down
9 changes: 7 additions & 2 deletions app/AppKernel.php
@@ -1,7 +1,10 @@
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\ClassLoader\DebugUniversalClassLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
Expand All @@ -19,10 +22,12 @@ public function registerBundles()
new FOS\UserBundle\FOSUserBundle(),
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
new Snc\RedisBundle\SncRedisBundle(),
new Packagist\WebBundle\PackagistWebBundle(),
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new Nelmio\SolariumBundle\NelmioSolariumBundle(),
new Nelmio\SecurityBundle\NelmioSecurityBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),

new Packagist\WebBundle\PackagistWebBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -52,6 +52,8 @@

"kriswallsmith/assetic": "~1.2@alpha",
"pagerfanta/pagerfanta": "~1.0"
"knplabs/knp-menu-bundle": "*@dev",
"knplabs/knp-menu": "*@dev"
},
"scripts": {
"post-install-cmd": [
Expand Down
49 changes: 49 additions & 0 deletions src/Packagist/WebBundle/Menu/MenuBuilder.php
@@ -0,0 +1,49 @@
<?php

namespace Packagist\WebBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class MenuBuilder
{
private $factory;

/**
* @param FactoryInterface $factory
*/
public function __construct(FactoryInterface $factory)
{
$this->factory = $factory;
}

public function createUserMenu()
{
$menu = $this->factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav-user-menu');

$menu->addChild('Profile', array('label' => '<span class="icon-vcard"></span>Profile', 'route' => 'fos_user_profile_show', 'extras' => array('safe_label' => true)));
$menu->addChild('Settings', array('label' => '<span class="icon-tools"></span>Settings', 'route' => 'fos_user_profile_edit', 'extras' => array('safe_label' => true)));
$menu->addChild('Change password', array('label' => '<span class="icon-key"></span>Change password', 'route' => 'fos_user_change_password', 'extras' => array('safe_label' => true)));
$menu->addChild('My packages', array('label' => '<span class="icon-box"></span>My packages', 'route' => 'user_packages', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
$menu->addChild('My favorites', array('label' => '<span class="icon-leaf"></span>My favorites', 'route' => 'user_favorites', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
$menu->addChild('hr', array('label' => '<hr>', 'labelAttributes' => array('class' => 'normal'), 'extras' => array('safe_label' => true)));
$menu->addChild('Logout', array('label' => '<span class="icon-off"></span>Logout', 'route' => 'logout', 'extras' => array('safe_label' => true)));

return $menu;
}

public function createProfileMenu()
{
$menu = $this->factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav nav-tabs nav-stacked');

$menu->addChild('Profile', array('label' => '<span class="icon-vcard"></span>Profile', 'route' => 'fos_user_profile_show', 'extras' => array('safe_label' => true)));
$menu->addChild('Edit your information', array('label' => '<span class="icon-tools"></span>Edit your information', 'route' => 'fos_user_profile_edit', 'extras' => array('safe_label' => true)));
$menu->addChild('Change password', array('label' => '<span class="icon-key"></span>Change password', 'route' => 'fos_user_change_password', 'extras' => array('safe_label' => true)));
$menu->addChild('View your packages', array('label' => '<span class="icon-box"></span>View your packages', 'route' => 'user_packages', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
$menu->addChild('View your favorites', array('label' => '<span class="icon-leaf"></span>View your favorites', 'route' => 'user_favorites', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));

return $menu;
}
}
22 changes: 22 additions & 0 deletions src/Packagist/WebBundle/Resources/config/services.yml
Expand Up @@ -86,3 +86,25 @@ services:
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: packagist_user_profile }

packagist.menu_builder:
class: Packagist\WebBundle\Menu\MenuBuilder
arguments: ["@knp_menu.factory"]

packagist.menu.user:
class: Knp\Menu\MenuItem
factory_service: packagist.menu_builder
factory_method: createUserMenu
arguments: ["@request"]
scope: request
tags:
- { name: knp_menu.menu, alias: user_menu }

packagist.menu.profile:
class: Knp\Menu\MenuItem
factory_service: packagist.menu_builder
factory_method: createProfileMenu
arguments: ["@request"]
scope: request
tags:
- { name: knp_menu.menu, alias: profile_menu }

0 comments on commit f078ea5

Please sign in to comment.