mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 06:01:35 +01:00
Refactored Menu and implemented event listener for node
This commit is contained in:
parent
cde432a4b4
commit
064ca5981c
@ -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\:
|
||||
|
@ -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 = [];
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user