mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +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']
|
factory: ['@app.menu_builder', 'sourceNavbar']
|
||||||
tags:
|
tags:
|
||||||
- { name: knp_menu.menu, alias: sourceNavbar }
|
- { 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
|
# makes classes in src/ available to be used as services
|
||||||
# this creates a service per class whose id is the fully-qualified class name
|
# this creates a service per class whose id is the fully-qualified class name
|
||||||
App\:
|
App\:
|
||||||
|
@ -13,10 +13,13 @@ final class MenuEventType extends AbstractEnumType
|
|||||||
{
|
{
|
||||||
public const USER = 'app.menu.topbar.user';
|
public const USER = 'app.menu.topbar.user';
|
||||||
|
|
||||||
public const SOURCE = 'app.menu.source.user';
|
public const SOURCE = 'app.menu.subbar.source';
|
||||||
|
|
||||||
protected static $choices = [
|
public const NODE = 'app.menu.subbar.node';
|
||||||
self::USER => self::USER,
|
|
||||||
self::SOURCE => self::SOURCE,
|
/**
|
||||||
];
|
* May this will be used in the future
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $choices = [];
|
||||||
}
|
}
|
||||||
|
@ -27,29 +27,32 @@ class Menu
|
|||||||
$this->factory = $factory;
|
$this->factory = $factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SourceNavbar(RequestStack $request): ItemInterface
|
public function sourceNavbar(RequestStack $request): ItemInterface
|
||||||
{
|
{
|
||||||
$menu = $this->factory->createItem('root', [
|
$menu = $this->createBasicMenuItem();
|
||||||
'childrenAttributes' => [
|
|
||||||
'class' => 'navbar-nav mr-auto',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->dispatcher->dispatch(MenuEventType::SOURCE, new MenuEvent($this->factory, $menu, $request));
|
$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;
|
return $menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function userTopbar(RequestStack $request): ItemInterface
|
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' => [
|
'childrenAttributes' => [
|
||||||
'class' => 'navbar-nav mr-auto',
|
'class' => 'navbar-nav mr-auto',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->dispatcher->dispatch(MenuEventType::USER, new MenuEvent($this->factory, $menu, $request));
|
|
||||||
|
|
||||||
return $menu;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Subscriber;
|
namespace App\Subscriber;
|
||||||
|
|
||||||
|
use App\DBAL\Types\MenuEventType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -11,7 +13,7 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber
|
|||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
MenuEventType::NODE => 'onNodeMenuConfigure'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user