MenuBuilder::createMainMenu()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Vivait\BootstrapBundle\Menu;
4
5
use Knp\Menu\FactoryInterface;
6
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7
use Vivait\BootstrapBundle\Event\ConfigureMenuEvent;
8
9
class MenuBuilder {
10
	private $factory;
11
12
	private $event_dispatcher;
13
14
	/**
15
	 * @param FactoryInterface $factory
16
	 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
17
	 */
18
	public function __construct(FactoryInterface $factory, EventDispatcherInterface $event_dispatcher) {
19
		$this->factory = $factory;
20
		$this->event_dispatcher = $event_dispatcher;
21
	}
22
23
	public function createMainMenu() {
24
		$menu = $this->factory->createItem('root');
25
26
		$menu->addChild('main', [
27
			'navbar' => true
28
		]);
29
30
		// TODO: Move me to a listener so I can be ordered/prioritised
31
		$menu->addChild('search', [
32
			'navbar' => true,
33
			'pull-right' => true
34
		])->setExtra('template', 'VivaitBootstrapBundle:Default:search.html.twig');
35
36
		$this->event_dispatcher->dispatch(ConfigureMenuEvent::CONFIGURE, new ConfigureMenuEvent($this->factory, $menu));
37
38
39
		return $menu;
40
	}
41
}
42