mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
improve menucomposer to handle parameters and translation in old api
This commit is contained in:
@@ -6,6 +6,7 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
use Knp\Menu\FactoryInterface;
|
||||
use Knp\Menu\ItemInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,12 @@ class MenuComposer
|
||||
*/
|
||||
private $menuFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var
|
||||
@@ -40,10 +47,12 @@ class MenuComposer
|
||||
|
||||
function __construct(
|
||||
RouterInterface $router,
|
||||
FactoryInterface $menuFactory
|
||||
FactoryInterface $menuFactory,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->router = $router;
|
||||
$this->menuFactory = $menuFactory;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,6 +83,7 @@ class MenuComposer
|
||||
|
||||
foreach ($routeCollection->all() as $routeKey => $route) {
|
||||
if ($route->hasOption('menus')) {
|
||||
|
||||
if (array_key_exists($menuId, $route->getOption('menus'))) {
|
||||
$route = $route->getOption('menus')[$menuId];
|
||||
|
||||
@@ -99,9 +109,9 @@ class MenuComposer
|
||||
|
||||
// build menu from routes
|
||||
foreach ($routes as $order => $route) {
|
||||
$menu->addChild($route['label'], [
|
||||
$menu->addChild($this->translator->trans($route['label']), [
|
||||
'route' => $route['key'],
|
||||
'routeParameters' => $parameters,
|
||||
'routeParameters' => $parameters['args'],
|
||||
'order' => $order
|
||||
])
|
||||
->setExtras([
|
||||
@@ -114,7 +124,7 @@ class MenuComposer
|
||||
if ($this->hasLocalMenuBuilder($menuId)) {
|
||||
foreach ($this->localMenuBuilders[$menuId] as $builder) {
|
||||
/* @var $builder LocalMenuBuilderInterface */
|
||||
$builder->buildMenu($menuId, $menu, $parameters);
|
||||
$builder->buildMenu($menuId, $menu, $parameters['args']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user