public function RenderCheeseburgerMenuBlock::findActiveChild in Cheeseburger Menu 8.2
Same name and namespace in other branches
- 8.3 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::findActiveChild()
Find active link.
1 call to RenderCheeseburgerMenuBlock::findActiveChild()
- RenderCheeseburgerMenuBlock::renderTree in src/
Controller/ RenderCheeseburgerMenuBlock.php - Render given tree.
File
- src/
Controller/ RenderCheeseburgerMenuBlock.php, line 468 - Controller used for rendering block.
Class
- RenderCheeseburgerMenuBlock
- Class RenderCheeseburgerMenuBlock.
Namespace
Drupal\cheeseburger_menu\ControllerCode
public function findActiveChild($menuTree, $route_id, $current_url, $page_type) {
$statusArray['id'] = [];
$statusArray['url'] = [];
$statusArray['in'] = [];
foreach ($menuTree as $menus) {
foreach ($menus as $menu) {
if ($menu['id'] == $route_id && $page_type == $menu['type']) {
$statusArray['id'][] = $menu;
}
if ($current_url == $menu['url']) {
$statusArray['url'][] = $menu;
}
if (isset($menu['subitem']) && count($menu['subitem']) > 0) {
$this
->searchInSubtItems($menu['subitem'], $route_id, $current_url, $page_type, $statusArray);
}
}
}
if (count($statusArray['url']) == 1) {
return current($statusArray['url']);
}
if (count($statusArray['id']) == 1) {
return current($statusArray['id']);
}
$same = TRUE;
$first = TRUE;
if (count($statusArray['url']) > 1) {
foreach ($statusArray['url'] as $url) {
if ($first) {
$help = $url;
$first = FALSE;
}
else {
if ($help != $url) {
$same = FALSE;
}
}
}
if ($same) {
return $help;
}
}
$same = TRUE;
$first = TRUE;
if (count($statusArray['url']) > 1) {
foreach ($statusArray['id'] as $id) {
if ($first) {
$help = $id;
$first = FALSE;
}
else {
if ($help != $id) {
$same = FALSE;
}
}
}
if ($same) {
return $help;
}
}
if (count($statusArray['in']) == 1) {
return current($statusArray['in']);
}
return [];
}