/**
  * @param mixed $resource
  * @param null $type
  * @return RouteCollection
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add the "extra" loader twice');
     }
     $routes = new RouteCollection();
     $root = PageQuery::create()->findRoot();
     if (!$root) {
         $root = new Page();
         $root->setTitle('Home');
         $root->makeRoot();
         $root->save();
     }
     $module_route_groups = $this->getModuleRouteGroups();
     $module_route_array = array();
     foreach ($module_route_groups as $v) {
         $module_route_array[$v['routes']] = $v['name'];
     }
     /** @var Page $page */
     foreach ($root->getBranch() as $page) {
         $current_page = $page;
         $path = array();
         while ($parent_page = $page->getParent()) {
             $path[] = $page;
             $page = $parent_page;
         }
         $path = array_reverse($path);
         $path_str = '';
         /** @var Page $path_part */
         foreach ($path as $path_part) {
             $path_str .= '/' . $path_part->getSlug();
         }
         // Module (routes group)
         if ($current_page->getModule() && isset($module_route_array[$current_page->getModule()])) {
             $this->addModuleRoutes($current_page, $path_str, $routes);
         } else {
             $this->addPageRoute($current_page, $path_str, $routes);
         }
     }
     $this->loaded = true;
     return $routes;
 }
 /**
  * Ajax add Page
  *
  * @param Request $request
  * @return JsonResponse
  * @throws \Exception
  * @throws \PropelException
  */
 public function ajaxAddAction(Request $request)
 {
     if (false === $this->admin->isGranted('CREATE')) {
         throw new AccessDeniedException();
     }
     $parent = PageQuery::create()->findOneById($request->query->get('parentId'));
     if (!$parent) {
         throw new \Exception();
     }
     $page = new Page();
     $page->setLocale($request->getLocale());
     $page->setTitle($request->query->get('name'));
     $page->insertAsLastChildOf($parent);
     $page->save();
     $this->clearRouteCache();
     return new JsonResponse(array('id' => $page->getId()));
 }