router = $router; $this->menu_gen = $menu_gen; } public function getFunctions() { return [ new TwigFunction('menu_get', [$this, 'getMenu']), new TwigFunction('menu_link', [$this, 'getMenuLink']), ]; } public function getMenu($menu_group) { $menu_data = $this->menu_gen->getMenu($menu_group); if (isset($menu_data['menu'])) return $menu_data['menu']; return []; } public function getMenuLink($mi) { // generate a link URL from a menu item // NOTE: right now we only use routes try { $link = $this->router->generate($mi->getID()); } catch (RouteNotFoundException $e) { $link = ''; } return $link; } }