I have a method with reference in param. But when I'm trying to do recursive call, no values are saved to my array, although there should be 2 values in array. Here is my function, the problem is, when it's called again while checking $nodesArray[$nodeKey]['nodes']. That should check menu sub-nodes and give back that nodes, which the selected role can see. At the end of every foreach loop, I use dump($nodesArray). After last loop when checking subnodes, array has only the right values. But when it gets back to "main" loop, value of ['nodes'] is NULL. What could be wrong? Thank you!
private function filterMenuNodesByRole(& $nodesArray)
{
foreach ($nodesArray as $nodeKey => $nodeItem) {
$link = trim($nodeItem['href'], self::SEPARATOR_PRESENTER_LINK);
if ((substr($link, -1) == '!') && ($this->user->isInRole(AuthRoleEnum::SUPERADMIN) === false)) {
unset($nodesArray[$nodeKey]);
}
if (substr_count($link, self::SEPARATOR_PRESENTER_LINK) == 2) {
$resource = substr($link, 0, strrpos($link, self::SEPARATOR_PRESENTER_LINK));
$privilege = substr($link, strrpos($link, self::SEPARATOR_PRESENTER_LINK) + 1);
if ($this->user->isAllowed($resource, $privilege) === false) {
unset($nodesArray[$nodeKey]);
} else if (!empty($nodeItem['nodes'])) {
$nodesArray[$nodeKey]['nodes'] = $this->filterMenuNodesByRole($nodeItem['nodes']);
}
} else {
if (!empty($nodeItem['nodes'])) {
$nodesArray[$nodeKey]['nodes'] = $this->filterMenuNodesByRole($nodeItem['nodes']);
}
}
if (isset($nodeItem['nodes']) && count($nodeItem['nodes']) == 0) {
unset($nodesArray[$nodeKey]);
continue;
}
dump($nodesArray);
}
}