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 74
|
<?php
namespace Site\FrontBundle\Menu;
use Knp\Menu\FactoryInterface;
use Kpn\Menu\Iterator\CurrentItemFilterIterator;
use Kpn\Menu\Iterator\RecursiveItemIterator;
use Symfony\Component\DependencyInjection\ContainerAware;
/**
* Builder of the main menu
*
*/
class Builder extends ContainerAware {
public function mainMenu(FactoryInterface $factory, array $options) {
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav navbar-nav col-lg-5 col-md-5 col-sm-5');
$menu->setChildrenAttribute('id', 'main-menu');
$menu->setCurrent($this->container->get('request')->getRequestUri());
$menu->addChild('Accueil', array(
'route' => 'site_front_homepage',
'attributes' => array('class' => 'nav-header')
));
$menu->addChild('Tutoriels', array(
'route' => 'site_front_tutorial',
'attributes' => array('class' => 'nav-header')
));
$menu->addChild('A propos', array(
'route' => 'site_front_about',
'attributes' => array('class' => 'nav-header')
));
$menu->addChild('Contact', array(
'route' => 'site_front_contact',
'attributes' => array('class' => 'nav-header')
));
return $menu;
}
/*
*
*/
public function breadCrumb(FactoryInterface $factory, array $options)
{
$menu = $this->mainMenu($factory, $options);
/* @var $matcher \Knp\Menu\Matcher\Matcher */
$matcher = $this->container->get('knp_menu.matcher');
$treeIterator = new RecursiveIteratorIterator(
new RecursiveItemIterator(
new ArrayIterator(array($menu))
), RecursiveIteratorIterator::SELF_FIRST
);
$iterator = new CurrentItemFilterIterator($treeIterator, $matcher);
// Set Current as an empty Item in order to avoid exceptions on knp_menu_get
$current = new MenuItem('', $factory);
foreach ($iterator as $item) {
$item->setCurrent(true);
$current = $item;
break;
}
return $current;
}
} |
Partager