2018-09-06 09:44:29 +02:00
|
|
|
<?php
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
namespace App\Menu;
|
|
|
|
|
|
|
|
use Knp\Menu\FactoryInterface;
|
|
|
|
use Knp\Menu\ItemInterface;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
2018-10-04 22:05:31 +02:00
|
|
|
use App\Event\Menu\MenuEvent;
|
|
|
|
use App\DBAL\Types\MenuEventType;
|
2018-09-06 09:44:29 +02:00
|
|
|
|
|
|
|
class Menu
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var EventDispatcherInterface
|
|
|
|
*/
|
|
|
|
private $dispatcher;
|
2018-09-12 23:25:22 +03:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
/**
|
|
|
|
* @var FactoryInterface
|
|
|
|
*/
|
|
|
|
private $factory;
|
2018-09-12 23:25:22 +03:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher)
|
|
|
|
{
|
|
|
|
$this->dispatcher = $dispatcher;
|
|
|
|
$this->factory = $factory;
|
|
|
|
}
|
2018-09-12 23:25:22 +03:00
|
|
|
|
2018-10-04 22:18:33 +02:00
|
|
|
public function sourceNavbar(RequestStack $request): ItemInterface
|
2018-09-20 14:26:28 +02:00
|
|
|
{
|
2018-10-04 22:22:47 +02:00
|
|
|
return $this->createMenu(MenuEventType::SOURCE, $request);
|
2018-10-04 22:18:33 +02:00
|
|
|
}
|
2018-10-04 22:22:47 +02:00
|
|
|
|
2018-10-04 22:18:33 +02:00
|
|
|
public function nodeSubbar(RequestStack $request): ItemInterface
|
|
|
|
{
|
2018-10-04 22:22:47 +02:00
|
|
|
return $this->createMenu(MenuEventType::NODE, $request);
|
2018-09-20 14:26:28 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
public function userTopbar(RequestStack $request): ItemInterface
|
|
|
|
{
|
2018-10-04 22:22:47 +02:00
|
|
|
return $this->createMenu(MenuEventType::USER, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createMenu(string $type, RequestStack $request): ItemInterface
|
|
|
|
{
|
|
|
|
$menu = $this->createBasicMenuItem();
|
|
|
|
$this->dispatcher->dispatch($type, new MenuEvent($this->factory, $menu, $request));
|
2018-10-29 19:01:00 +01:00
|
|
|
|
2018-10-04 22:18:33 +02:00
|
|
|
return $menu;
|
|
|
|
}
|
2018-10-04 22:22:47 +02:00
|
|
|
|
|
|
|
private function createBasicMenuItem(): ItemInterface
|
|
|
|
{
|
2018-10-04 22:18:33 +02:00
|
|
|
return $this->factory->createItem('root', [
|
2018-09-12 23:25:22 +03:00
|
|
|
'childrenAttributes' => [
|
2018-10-29 19:01:00 +01:00
|
|
|
'class' => 'navbar-nav mr-auto',
|
|
|
|
],
|
2018-09-12 23:25:22 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|