/** * @param string $slug * @return string */ public function pageSlugLinkFunction($slug) { $page = PageQuery::create()->findOneBySlug($slug); if ($page) { return $this->pageLinkFunction($page->getRouteName()); } else { return ''; } }
/** * Get page by id, if page not found or inactive thow exception * * @param $page_id * @return Page */ protected function getPageById($page_id) { $page = PageQuery::create()->findOneById($page_id); if (!$page) { throw $this->createNotFoundException($this->get('translator')->trans('etfostra_front_page_not_found')); } $page->setLocale($this->get('request')->getLocale()); if (!$page->getActive()) { throw $this->createNotFoundException($this->get('translator')->trans('etfostra_front_page_not_found')); } return $page; }
/** * @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; }
/** * @param Request $request * @return JsonResponse * @throws \Exception * @throws \PropelException */ public function ajaxDetailsAction(Request $request) { if (false === $this->admin->isGranted('VIEW')) { throw new AccessDeniedException(); } $page = PageQuery::create()->findOneById($request->query->get('id')); if (!$page) { throw new NotFoundHttpException(); } $page->setLocale($request->getLocale()); if ($page->hasParent()) { $page->getParent()->setLocale($page->getLocale()); } $html = $this->renderView('EtfostraContentBundle:SonataAdmin:list_details.html.twig', array('page' => $page)); return new JsonResponse(array('html' => $html)); }