integration of knp menu bundle

This commit is contained in:
2018-04-30 17:42:24 +02:00
parent 5c045abda4
commit 395787f1bb
10 changed files with 204 additions and 46 deletions

View File

@@ -64,7 +64,10 @@ class MenuTwig extends \Twig_Extension implements ContainerAwareInterface
public function getFunctions()
{
return [new \Twig_SimpleFunction('chill_menu',
array($this, 'chillMenu'), array('is_safe' => array('html')))
array($this, 'chillMenu'), array(
'is_safe' => array('html'),
'needs_environment' => true
))
];
}
@@ -81,17 +84,22 @@ class MenuTwig extends \Twig_Extension implements ContainerAwareInterface
* @param string $menuId
* @param mixed[] $params
*/
public function chillMenu($menuId, array $params = array())
public function chillMenu(\Twig_Environment $env, $menuId, array $params = array())
{
$resolvedParams = array_merge($this->defaultParams, $params);
$layout = $resolvedParams['layout'];
unset($resolvedParams['layout']);
$resolvedParams['routes'] = $this->menuComposer->getRoutesFor($menuId);
if ($this->menuComposer->hasLocalMenuBuilder($menuId) === false) {
$resolvedParams['routes'] = $this->menuComposer->getRoutesFor($menuId, $resolvedParams);
return $this->container->get('templating')
->render($layout, $resolvedParams);
return $env->render($layout, $resolvedParams);
} else {
$resolvedParams['menus'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams);
return $env->render($layout, $resolvedParams);
}
}
public function getName()