Refactored Menu and implemented event listener for node

This commit is contained in:
Kevin Frantz 2018-10-04 22:18:33 +02:00
parent cde432a4b4
commit 064ca5981c
4 changed files with 32 additions and 19 deletions

View File

@ -26,6 +26,11 @@ services:
factory: ['@app.menu_builder', 'sourceNavbar']
tags:
- { name: knp_menu.menu, alias: sourceNavbar }
app.menu.node:
class: Knp\Menu\MenuItem
factory: ['@app.menu_builder', 'nodeSubbar']
tags:
- { name: knp_menu.menu, alias: nodeSubbar }
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:

View File

@ -13,10 +13,13 @@ final class MenuEventType extends AbstractEnumType
{
public const USER = 'app.menu.topbar.user';
public const SOURCE = 'app.menu.source.user';
public const SOURCE = 'app.menu.subbar.source';
protected static $choices = [
self::USER => self::USER,
self::SOURCE => self::SOURCE,
];
public const NODE = 'app.menu.subbar.node';
/**
* May this will be used in the future
* @var array
*/
protected static $choices = [];
}

View File

@ -27,29 +27,32 @@ class Menu
$this->factory = $factory;
}
public function SourceNavbar(RequestStack $request): ItemInterface
public function sourceNavbar(RequestStack $request): ItemInterface
{
$menu = $this->factory->createItem('root', [
'childrenAttributes' => [
'class' => 'navbar-nav mr-auto',
],
]);
$menu = $this->createBasicMenuItem();
$this->dispatcher->dispatch(MenuEventType::SOURCE, new MenuEvent($this->factory, $menu, $request));
return $menu;
}
public function nodeSubbar(RequestStack $request): ItemInterface
{
$menu = $this->createBasicMenuItem();
$this->dispatcher->dispatch(MenuEventType::NODE, new MenuEvent($this->factory, $menu, $request));
return $menu;
}
public function userTopbar(RequestStack $request): ItemInterface
{
$menu = $this->factory->createItem('root', [
$menu = $this->createBasicMenuItem();
$this->dispatcher->dispatch(MenuEventType::USER, new MenuEvent($this->factory, $menu, $request));
return $menu;
}
private function createBasicMenuItem():ItemInterface{
return $this->factory->createItem('root', [
'childrenAttributes' => [
'class' => 'navbar-nav mr-auto',
],
]);
$this->dispatcher->dispatch(MenuEventType::USER, new MenuEvent($this->factory, $menu, $request));
return $menu;
}
}

View File

@ -1,6 +1,8 @@
<?php
namespace App\Subscriber;
use App\DBAL\Types\MenuEventType;
/**
*
* @author kevinfrantz
@ -11,7 +13,7 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber
public static function getSubscribedEvents()
{
return [
MenuEventType::NODE => 'onNodeMenuConfigure'
];
}
}