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:
|
||||
- '@Symfony\Component\Routing\RouterInterface'
|
||||
- '@Knp\Menu\FactoryInterface'
|
||||
- '@Symfony\Component\Translation\TranslatorInterface'
|
||||
Chill\MainBundle\Routing\MenuComposer: '@chill.main.menu_composer'
|
||||
|
||||
chill.main.routes_loader:
|
||||
|
@ -64,7 +64,9 @@ Advanced search: Recherche avancée
|
||||
#admin
|
||||
Create: Créer
|
||||
show: voir
|
||||
Show: Voir
|
||||
edit: modifier
|
||||
Edit: Modifier
|
||||
Main admin menu: Menu d'administration principal
|
||||
Actions: Actions
|
||||
Users and permissions: Utilisateurs et permissions
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user