You are here

public function renderCheeseburgerMenuBlock::findChildren in Cheeseburger Menu 8

Same name and namespace in other branches
  1. 8.2 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::findChildren()
  2. 8.3 src/Controller/RenderCheeseburgerMenuBlock.php \Drupal\cheeseburger_menu\Controller\RenderCheeseburgerMenuBlock::findChildren()
1 call to renderCheeseburgerMenuBlock::findChildren()
renderCheeseburgerMenuBlock::getMenuTree in src/Controller/renderCheeseburgerMenuBlock.php

File

src/Controller/renderCheeseburgerMenuBlock.php, line 380

Class

renderCheeseburgerMenuBlock

Namespace

Drupal\cheeseburger_menu\Controller

Code

public function findChildren($menu) {
  $menu_tree_formatted = [];
  if (is_iterable($menu)) {
    foreach ($menu as $menu_data) {
      if ($menu_data['url']
        ->isRouted()) {
        $help_array = [];
        $help_array['subitem'] = $this
          ->findChildren($menu_data['below']);
        $help_array['name'] = $menu_data['title'];
        try {
          $help_array['id'] = $menu_data['url']
            ->getRouteParameters();
        } catch (\Exception $exception) {
          $help_array['id'][0] = NULL;
        }
        if (reset($help_array['id']) != NULL) {
          $help_array['type'] = key($help_array['id']);
          $help_array['id'] = reset($help_array['id']);
        }
        else {
          try {
            $help_array['id'] = $menu_data['url']
              ->getRouteName();
          } catch (\Exception $exception) {
            $help_array['id'] = NULL;
          }
          if ($help_array['id'] == "user.page") {
            $user = \Drupal::currentUser();
            $help_array['id'] = $user != NULL ? $user
              ->id() : $user;
            $help_array['type'] = 'user';
          }
          else {
            $help_array['type'] = 'view';
          }
        }
        try {
          $route_name = $menu_data['url']
            ->getRouteName();
        } catch (\Exception $exception) {
          $route_name = NULL;
        }
        if ($route_name != NULL) {
          $url = \Drupal\Core\Url::fromRoute($menu_data['url']
            ->getRouteName(), $menu_data['url']
            ->getRouteParameters());
          $help_array['url'] = $url
            ->toString();
        }
        else {
          $help_array['url'] = '';
        }
        $menu_tree_formatted[] = $help_array;
      }
    }
  }
  return $menu_tree_formatted;
}