mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
improve menucomposer to handle parameters and translation in old api
This commit is contained in:
parent
3908f32942
commit
0c4a27e759
@ -4,6 +4,7 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
- '@Symfony\Component\Routing\RouterInterface'
|
- '@Symfony\Component\Routing\RouterInterface'
|
||||||
- '@Knp\Menu\FactoryInterface'
|
- '@Knp\Menu\FactoryInterface'
|
||||||
|
- '@Symfony\Component\Translation\TranslatorInterface'
|
||||||
Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer'
|
Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer'
|
||||||
|
|
||||||
chill.main.routes_loader:
|
chill.main.routes_loader:
|
||||||
|
@ -64,7 +64,9 @@ Advanced search: Recherche avancée
|
|||||||
#admin
|
#admin
|
||||||
Create: Créer
|
Create: Créer
|
||||||
show: voir
|
show: voir
|
||||||
|
Show: Voir
|
||||||
edit: modifier
|
edit: modifier
|
||||||
|
Edit: Modifier
|
||||||
Main admin menu: Menu d'administration principal
|
Main admin menu: Menu d'administration principal
|
||||||
Actions: Actions
|
Actions: Actions
|
||||||
Users and permissions: Utilisateurs et permissions
|
Users and permissions: Utilisateurs et permissions
|
||||||
|
@ -6,6 +6,7 @@ use Symfony\Component\Routing\RouteCollection;
|
|||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Knp\Menu\FactoryInterface;
|
use Knp\Menu\FactoryInterface;
|
||||||
use Knp\Menu\ItemInterface;
|
use Knp\Menu\ItemInterface;
|
||||||
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,12 @@ class MenuComposer
|
|||||||
*/
|
*/
|
||||||
private $menuFactory;
|
private $menuFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var TranslatorInterface
|
||||||
|
*/
|
||||||
|
private $translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var
|
* @var
|
||||||
@ -40,10 +47,12 @@ class MenuComposer
|
|||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
RouterInterface $router,
|
RouterInterface $router,
|
||||||
FactoryInterface $menuFactory
|
FactoryInterface $menuFactory,
|
||||||
|
TranslatorInterface $translator
|
||||||
) {
|
) {
|
||||||
$this->router = $router;
|
$this->router = $router;
|
||||||
$this->menuFactory = $menuFactory;
|
$this->menuFactory = $menuFactory;
|
||||||
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +83,7 @@ class MenuComposer
|
|||||||
|
|
||||||
foreach ($routeCollection->all() as $routeKey => $route) {
|
foreach ($routeCollection->all() as $routeKey => $route) {
|
||||||
if ($route->hasOption('menus')) {
|
if ($route->hasOption('menus')) {
|
||||||
|
|
||||||
if (array_key_exists($menuId, $route->getOption('menus'))) {
|
if (array_key_exists($menuId, $route->getOption('menus'))) {
|
||||||
$route = $route->getOption('menus')[$menuId];
|
$route = $route->getOption('menus')[$menuId];
|
||||||
|
|
||||||
@ -99,9 +109,9 @@ class MenuComposer
|
|||||||
|
|
||||||
// build menu from routes
|
// build menu from routes
|
||||||
foreach ($routes as $order => $route) {
|
foreach ($routes as $order => $route) {
|
||||||
$menu->addChild($route['label'], [
|
$menu->addChild($this->translator->trans($route['label']), [
|
||||||
'route' => $route['key'],
|
'route' => $route['key'],
|
||||||
'routeParameters' => $parameters,
|
'routeParameters' => $parameters['args'],
|
||||||
'order' => $order
|
'order' => $order
|
||||||
])
|
])
|
||||||
->setExtras([
|
->setExtras([
|
||||||
@ -114,7 +124,7 @@ class MenuComposer
|
|||||||
if ($this->hasLocalMenuBuilder($menuId)) {
|
if ($this->hasLocalMenuBuilder($menuId)) {
|
||||||
foreach ($this->localMenuBuilders[$menuId] as $builder) {
|
foreach ($this->localMenuBuilders[$menuId] as $builder) {
|
||||||
/* @var $builder LocalMenuBuilderInterface */
|
/* @var $builder LocalMenuBuilderInterface */
|
||||||
$builder->buildMenu($menuId, $menu, $parameters);
|
$builder->buildMenu($menuId, $menu, $parameters['args']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user