vendor/elcoag/symfony-process-bundle/src/EventSubscriber/KnpMenuBuilderSubscriber.php line 41
<?php
namespace Elcoag\SymfonyProcessBundle\EventSubscriber;
use Elcoag\SymfonyAdminlteBundle\Event\KnpMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* Class KnpMenuBuilderSubscriber configures the main navigation utilizing the KnpMenuBundle.
*/
class KnpMenuBuilderSubscriber implements EventSubscriberInterface
{
/**
* @var AuthorizationCheckerInterface
*/
private $security;
/**
* @param AuthorizationCheckerInterface $security
*/
public function __construct(AuthorizationCheckerInterface $security)
{
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
KnpMenuEvent::class => ['onSetupNavbar', 100],
];
}
/**
* Generate the main menu.
*
* @param KnpMenuEvent $event
*/
public function onSetupNavbar(KnpMenuEvent $event)
{
/*
$config = [
'menu-label' => ['label' => 'Process'],
'process_docs' => ['label' => 'Docs', 'icon' => 'fas fa-book'],
'process_list' => ['label' => 'List', 'icon' => 'fas fa-list', 'badges' => [['value' => 'all', 'color' => 'red']]],
'process_create' => ['label' => 'Create', 'icon' => 'fas fa-plus'],
];
$this->addMenuItemsByConfig($event, $config);*/
$config = [
'menu-label_server' => ['label' => 'Server'],
'app_server_index' => ['label' => 'List', 'icon' => 'fas fa-list'],
'app_server_new' => ['label' => 'New', 'icon' => 'fas fa-plus'],
'menu-label_process' => ['label' => 'Process'],
'app_process_index' => ['label' => 'List', 'icon' => 'fas fa-list'],
'app_process_new' => ['label' => 'New', 'icon' => 'fas fa-plus'],
//'process_show' => ['label' => 'List', 'icon' => 'fas fa-list', 'badges' => [['value' => 'all', 'color' => 'red']]],
//'process_show' => ['label' => 'Create', 'icon' => 'fas fa-plus'],
];
$this->addMenuItemsByConfig($event, $config);
}
/**
* Add menu items by config
*
* @param KnpMenuEvent $event
* @param array $config
*/
public function addMenuItemsByConfig(KnpMenuEvent $event, array $config)
{
$menu = $event->getMenu();
foreach ($config as $route => $item) {
if(strpos($route, 'divider') === 0) {
$menu->addChild($route, ['label' => '<hr />'])->setExtra('safe_label', true);
} else if(strpos($route, 'menu-label') === 0) {
$menu->addChild($route, ['label' => $item['label'], 'childOptions' => $event->getChildOptions()]);
} else {
$menuItem = $menu->addChild(
$route,
['route' => $item['route'] ?? $route, 'routeParameters' => $item['routeParameters'] ?? [], 'label' => $item['label'], 'childOptions' => $event->getChildOptions()]
);
if(isset($item['icon'])){
$menuItem->setLabelAttribute('icon', $item['icon']);
}
if(isset($item['badges'])){
$menuItem->setExtra('badges', $item['badges']);
}
if(isset($item['badge'])){
$menuItem->setExtra('badge', $item['badge']);
}
}
}
}
}