Kunstmaan / KunstmaanMenuBundle

[READ-ONLY] Subtree split of the Kunstmaan MenuBundle -- master at Kunstmaan/KunstmaanBundlesCMS
https://bundles.kunstmaan.be
MIT License
3 stars 0 forks source link

Active state in RenderService in dev env #3

Open jazzzpor opened 7 years ago

jazzzpor commented 7 years ago

When using the "get_menu" Twig function, the active state for the menu items is not properly detected in the 'dev' environment.

The problem lies in the RenderService:

$url = $this->router->generate('_slug', array('url' => $node['nodeTranslation']['url']));

if ($this->router->getContext()->getPathInfo() == $url) {
    $active = true;
}

Because I am working in 'dev' environment, the base url the context of the router is "/app_dev.php". The path info of the context does not contain the base url so it will never match the generated url.

Currently I implemented a hack like this:

if ($this->router->getContext()->getPathInfo() === str_replace('/app_dev.php', '', $url)) {
     $active = true;
}

It's not pretty so I'm hoping you have a better solution ;-)