I use the regexVoter from knpMenu like this
//This is on my createMenuAction
$this->matchingRoute($menu);
/**
* @param $menu
*
* @return bool
*/
private function matchingRoute($menu)
{
foreach ($menu->getChildren() as $child) {
$childRegex = $child->getAttribute('regex');
$voter = new RegexVoter($childRegex);
$voterTest = $voter->matchItem($child);
if ($voterTest == true && $this->request->getUri()) {
$child->setCurrent(true);
} else {
$child->setCurrent(false);
}
}
}
This is working but setting me a current class to all child with a regex attributes. This voter compare childs regex with their route so it become true all the time.
I tried to add return true;
if ($voterTest == true && $this->request->getUri()) {
$child->setCurrent(true);
return true;
} else {
$child->setCurrent(false);
}
But this set current class on the first child who return true with regexVoter.
Should i check this regex against the current route with this voter ?
How can i use this voter to set current class on the good child ?
Thanks,